I currently have a class that looks like the following .
我目前有一个类如下所示。
#define SET_METHOD( t , n ) \
private: t n; \
public: void set_##n( t value ) { n = value; }
class SomeClass
{
private:
SET_METHOD(std::map<int,SomeClass>,hf);
};
However when I do something like this :
但是,当我做这样的事情时:
SomeClass sc;
hc.AddItem(1,sc);
I get the following error. I have also these macros for setting up getters and setters but this time I dont know what the problem is. I am getting the following error
我收到以下错误。我还有这些用于设置getter和setter的宏,但这次我不知道问题是什么。我收到以下错误
Error 3 error C2923: 'std::map' : 'SomeClass' is not a valid template type argument for parameter '_Ty'
Error 4 error C2208: 'std::map<_Kty,_Ty>' : no members defined using this type
Any suggestion on how to resolve this issue would be appreciated
任何有关如何解决此问题的建议将不胜感激
2 个解决方案
#1
4
I believe the ,
in the definition std::map<int,SomeClass>
is confusing the C++ pre-processor.
我相信,在定义std :: map
Drop the macros and define your setters/getters by hand.
放下宏并手动定义你的setter / getters。
Alternatively create a typedef
:
或者创建一个typedef:
typedef std::map<int,SomeClass> MyMap;
and use:
IMPLEMENT_SET_GET_METHOD(MyMap,hf);
#2
0
Is there a conversion from HistoricalFields type to SomeClass type? You are also trying to define your class member in terms of class itself which leads to to a chicken/egg problem (you a trying to define a member which is a collection containig the outer class itself).
是否有从HistoricalFields类型到SomeClass类型的转换?你也试图用类本身来定义你的类成员,这会导致鸡/蛋问题(你试图定义一个成员,它是一个包含外部类本身的集合)。
#1
4
I believe the ,
in the definition std::map<int,SomeClass>
is confusing the C++ pre-processor.
我相信,在定义std :: map
Drop the macros and define your setters/getters by hand.
放下宏并手动定义你的setter / getters。
Alternatively create a typedef
:
或者创建一个typedef:
typedef std::map<int,SomeClass> MyMap;
and use:
IMPLEMENT_SET_GET_METHOD(MyMap,hf);
#2
0
Is there a conversion from HistoricalFields type to SomeClass type? You are also trying to define your class member in terms of class itself which leads to to a chicken/egg problem (you a trying to define a member which is a collection containig the outer class itself).
是否有从HistoricalFields类型到SomeClass类型的转换?你也试图用类本身来定义你的类成员,这会导致鸡/蛋问题(你试图定义一个成员,它是一个包含外部类本身的集合)。