开发者

some problems when using std set

开发者 https://www.devze.com 2023-04-04 18:40 出处:网络
all, I have created the following code: struct Styles{ wstring styleVal; wstring styleName; }; set<Styles> vtrStyles1;//filled in somehow

all, I have created the following code:

struct Styles{
wstring styleVal;
wstring styleName;
};
set<Styles> vtrStyles1;//filled in somehow
set<Styles> vtrStyles2;//filled in somehow

set<Styles> vtrStyles3(vtrStyles1);
vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
unCommon = vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();

I have included set in stdafx.h, and using namespace std; but i got the following errors:

1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5377): error C2275: 'Styles' : illegal use of this type as an expression
1>          XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5377): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5378): error C2275: 'Styles' : illegal use of this type as an expression
1>          XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5378): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5497): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5507): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5507): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5517): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5517): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5534): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5534): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5545): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5545): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5555): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5555): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5565): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5565): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5606): error C2开发者_JS百科065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5606): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5616): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5616): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5626): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5626): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5643): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5643): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5654): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5654): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5664): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5664): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5674): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5674): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'set' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C2275: 'Styles' : illegal use of this type as an expression
1>          XMLDOMFromVCDlg.cpp(5344) : see declaration of 'Styles'
1>XMLDOMFromVCDlg.cpp(5704): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5704): error C3861: 'vtrStyles3': identifier not found
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.insert' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.begin' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5705): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5705): error C2228: left of '.end' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles1' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles2' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5706): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5706): error C2228: left of '.size' must have class/struct/union
1>          type is ''unknown-type''
1>XMLDOMFromVCDlg.cpp(5707): error C2065: 'vtrStyles3' : undeclared identifier
1>XMLDOMFromVCDlg.cpp(5707): error C2228: left of '.size' must have class/struct/union
1>          type is ''unknown-type''

so whats going on? thx in advance.

cheers

daiyue


There's something you're not telling us. The following program (copy-pasted by parts from your posted code) compiles fine using Visual Studio 2008, provided that you define operator< for your Styles struct (see below).

#include <set>
#include <string>
using namespace std;

struct Styles {
    wstring styleVal;
    wstring styleName;
};

int main ( int, char ** )
{
    set<Styles> vtrStyles1;
    set<Styles> vtrStyles2;
    set<Styles> vtrStyles3(vtrStyles1);
    vtrStyles3.insert(vtrStyles2.begin(), vtrStyles2.end());
    const size_t unCommon =
        vtrStyles1.size() + vtrStyles2.size() - vtrStyles3.size();
}

The following definition seems OK to me, but it might not be what you have in mind. Insert this before main().

bool operator< ( const Styles& lhs, const Styles& rhs )
{
    return (lhs.styleName < rhs.styleName);
}

If you can compile this program, then your problem lies elsewhere.


You need to either use std::set or using std::set or using namespace std. Also, make sure

#include <set> 

in either stdafx.h or in your code.


Assuming you've edited stdafx.h to #include <set> and added using namespace std, did you hit Ctrl+F7 to just compile XMLDOMFromVCDlg.cpp? If so, you need to recompile stdafx.cpp first to regenerate the precompiled header.

0

精彩评论

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