在头文件中声明一个地图? [英] Declaring a map in the header file?
问题描述
我有以下代码snippit编译器不会采取(vc
++ 6)。我想将一个地图作为一个类中的成员变量。所以
我把它放到了头文件中,并且它不会用
描述符,但它不喜欢它,如果我把它们带出去。
(在我的班级.h文件中)
#include< map>
class PRGEdit {
....
protected:
map< CString,Keyword,strCmpkeywordMap();
.....
};
struct strCmp {
bool operator()(const char * s1,const char * s2)const {
返回strcmp(s1,s2)< 0;
}
};
类关键字{
public:
关键字();
关键字(CString newname);
~关键字();
CString名称;
CHARFORMAT * cf;
};
输出:
c:\\ \\ ... \ progeditordlg.h(81):错误C2143:语法错误:缺少'';''
之前''<''
c:\\ \\ ... \ progeditordlg.h(81):错误C2501:''map'':缺少存储空间 -
类或类型说明符
c:\ .. .\progeditordlg.h(81):错误C2059:语法错误:''<''
c:\ ... \ progeditordlg.h(81):错误C2238:意外令牌(s)
在''之前;'''
我明白我声明它可能会在.cpp中使用
文件,但是如何将其声明为类的实例变量?
谢谢,
~Scoots
I have the following code snippit that the compiler just won''t take (vc
++ 6). I want to make a map as a member variable inside a class. So
I''ve put it into the header file, and it won''t take it with the
descriptors, but it doesn''t like it if I take them out, either.
(inside my class .h file)
#include <map>
class PRGEdit{
....
protected:
map <CString, Keyword, strCmpkeywordMap();
.....
};
struct strCmp {
bool operator()( const char* s1, const char* s2 ) const {
return strcmp( s1, s2 ) < 0;
}
};
class Keyword{
public:
Keyword();
Keyword(CString newname);
~Keyword();
CString name;
CHARFORMAT* cf;
};
Output:
c:\...\progeditordlg.h(81) : error C2143: syntax error : missing '';''
before ''<''
c:\...\progeditordlg.h(81) : error C2501: ''map'' : missing storage-
class or type specifiers
c:\...\progeditordlg.h(81) : error C2059: syntax error : ''<''
c:\...\progeditordlg.h(81) : error C2238: unexpected token(s)
preceding '';''
I understand that I''m declaring it like it might be used in a .cpp
file, but how do I declare this as a instance variable of the class?
Thanks,
~Scoots
推荐答案
Scoots写道:
Scoots wrote:
我有以下代码snippit编译器不会采取
(vc ++ 6)。
I have the following code snippit that the compiler just won''t take
(vc ++ 6).
考虑获得一个更好的编译器,无论你是否得到这个
的情况。
Consider getting a better compiler regardless of whether you get this
case to work.
我想把一个地图作为一个类中的成员变量。
所以我把它放到头文件中,它不会带它
描述符,但是如果我把它们取出来它也不喜欢它。
(在我的班级.h文件中)
#include< map>
class PRGEdit {
...
protected:
map< CString,Keyword,strCmpkeywordMap();
I want to make a map as a member variable inside a class.
So I''ve put it into the header file, and it won''t take it with the
descriptors, but it doesn''t like it if I take them out, either.
(inside my class .h file)
#include <map>
class PRGEdit{
...
protected:
map <CString, Keyword, strCmpkeywordMap();
应该是
std :: map< ...
(std ::部分非常重要)。阅读命名空间。
Should be
std::map < ...
(the "std::" part is important). Read up about namespaces.
....
};
[..]
....
};
[..]
V
-
请在通过电子邮件回复时删除资金'A'
我没有回复最热门的回复,请不要问
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
哦,是的,''()''在我只是在
中添加了keywordMap以尝试获得更具描述性的错误,该行是:
map< CString,Keyword,strCmpkeywordMap;
Oh, and yes, the ''()'' on the keywordMap was something I added in just
to try and get a more descriptive error, the line was:
map <CString, Keyword, strCmpkeywordMap;
啊,谢谢。忘记使用命名空间std;感谢及时
回复。
至于更好的编译器,我同意。我在我的
家用机器上使用过VS.NET PRO 2003,但不幸的是,我是一名夏季实习生。我没有这么好的杠杆。
无论如何感谢你的帮助!我现在觉得有点不可思议......
ahh, thanks. Forgot the using namespace std; Thanks for the timely
reply.
As for the better compiler, I agree. I''ve used VS.NET PRO 2003 on my
home machine, but unfotunately, I''m a summer intern here. I don''t
have that kind of leverage.
Anyway thanks for the help! I feel slightly rediculous now...
这篇关于在头文件中声明一个地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!