开发者

Anonymous types in C++

I was wondering if there is any equivalent, or a way to fake, C# style anonymous types in C++. I'm using gcc 4.6 so any parts of C++0开发者_如何学运维x it supports can be used.


If you’re looking for a container that can hold a “bag” of different types, the closest analog would be std::tuple.


You can sort of fake it with a std::map<std::string, boost::any>, but that's really not the same. There's no way to get anything truly like C# 3+'s anonymous types in C++.

Anonymous types are really only useful for LINQ anyway, and C++ doesn't support anything like that either, so it's unlikely that such would be useful anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜