STL problem
-
Hi, Im trying to use STL in my MFC program in VC++. It keeps on giving me errors. Im sure there is a simple way to fix it, but i have no idea what that way is. Can someone help? Cheers Dor
Well, unless you give us some details of the problem, you might be better off trying here[^]... :-)
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.
-
Well, unless you give us some details of the problem, you might be better off trying here[^]... :-)
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.
-
Taka Muraoka wrote: you might be better off trying here[^]... LOL Yeah please post the error you are getting..
Well, i include all the right things and it gives me this error on the line that i declare the list object on: c:\program files\microsoft visual studio\vc98\include\ios.h(146) : error C2872: 'streambuf' : ambiguous symbol I know that the code works when its not using MFC, this error only comes up when in an MFC project Cheers Dor
-
Well, i include all the right things and it gives me this error on the line that i declare the list object on: c:\program files\microsoft visual studio\vc98\include\ios.h(146) : error C2872: 'streambuf' : ambiguous symbol I know that the code works when its not using MFC, this error only comes up when in an MFC project Cheers Dor
This is almost certainly caused by your having #include'd mismatching files. Most STL objects come in two versions, one that lives in the global namespace (this is the old style) that you get by #include'ing <iostream.h> The newer version lives in the std namespace - you this by #include'ing <iostream> (nb: no ".h") So if you #include *both* files and have a using namespace std directive somewhere, when the compiler finds a reference to an STL class, streambuf in your case, it has two matching possibilities i.e. ::streambuf and std::streambuf and doesn't know which one to use.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.
-
This is almost certainly caused by your having #include'd mismatching files. Most STL objects come in two versions, one that lives in the global namespace (this is the old style) that you get by #include'ing <iostream.h> The newer version lives in the std namespace - you this by #include'ing <iostream> (nb: no ".h") So if you #include *both* files and have a using namespace std directive somewhere, when the compiler finds a reference to an STL class, streambuf in your case, it has two matching possibilities i.e. ::streambuf and std::streambuf and doesn't know which one to use.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.
But the
#include
only appears once in the project. should i be usingusing namespace std;
with this version, and should it appear in the header file of the class, and should it be global or local to the class? sorry, im bombarding you with questions! Cheers Dor -
But the
#include
only appears once in the project. should i be usingusing namespace std;
with this version, and should it appear in the header file of the class, and should it be global or local to the class? sorry, im bombarding you with questions! Cheers DorYou need to be careful when typing in #include statements here. the < looks like the start of an HTML tag and doesn't get processed properly - use < Never put "using namespace std" in a header file - it should always go in the .cpp file, *after* all your #include's. It is not something that is global/local to a class but instead something that relates to an entire file, during the compilation process. This kind of thing is almost impossible to track down without having access to a full copy of the source. The reason why it is working previously but not with MFC is that MFC is #include'ing its own version of the STL headers, probably the old .h ones while your code is #include'ing the new ones. I would try fiddling around with your #include's. You might want to turn off pre-compiled headers while you're doing this since it will almost certainly cause you grief :-)
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.
-
You need to be careful when typing in #include statements here. the < looks like the start of an HTML tag and doesn't get processed properly - use < Never put "using namespace std" in a header file - it should always go in the .cpp file, *after* all your #include's. It is not something that is global/local to a class but instead something that relates to an entire file, during the compilation process. This kind of thing is almost impossible to track down without having access to a full copy of the source. The reason why it is working previously but not with MFC is that MFC is #include'ing its own version of the STL headers, probably the old .h ones while your code is #include'ing the new ones. I would try fiddling around with your #include's. You might want to turn off pre-compiled headers while you're doing this since it will almost certainly cause you grief :-)
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) Awasu v0.4a[^]: A free RSS reader with support for Code Project.