Click to See Complete Forum and Search --> : Errors compiling Standard C++ code with VC++


May 24th, 1999, 11:20 AM
Environment: VC++ 6.0 SP2, WINNT 4.0 SP3
I created an MDI project using the wizard. Added a declaration
string s;
in the doc class
and included the header <string> (without .h)
(a) first in the implementation file for the doc, just above the include statament for its header. It didn't work, so I
(b) removed that statement and included it inside the header file (of the doc). This too, didn't work.
In both cases, I got the errors

d:\msvisualstudio\vc98\include\xmemory(39) : warning C4100: '_P' : unreferenced formal parameter
d:\msvisualstudio\vc98\include\xmemory(41) : warning C4100: '_P' : unreferenced formal parameter
d:\msvisualstudio\vc98\include\xlocale(296) : warning C4663: C++ language change: to explicitly specialize class template 'codecvt' use the following syntax:
template<> class codecvt<unsigned short,char,int> ...
d:\msvisualstudio\vc98\include\xlocale(387) : warning C4018: '<' : signed/unsigned mismatch
d:\msvisualstudio\vc98\include\xlocale(519) : warning C4663: C++ language change: to explicitly specialize class template 'ctype' use the following syntax:
template<> class ctype<char> ...
d:\msvisualstudio\vc98\include\xlocale(552) : warning C4100: '_D' : unreferenced formal parameter
d:\msvisualstudio\vc98\include\xlocale(554) : warning C4100: '_D' : unreferenced formal parameter
e:\pb\pbdoc.h(26) : error C2146: syntax error : missing ';' before identifier 's'
e:\pb\pbdoc.h(26) : error C2501: 'string' : missing storage-class or type specifiers
e:\pb\pbdoc.h(26) : error C2501: 's' : missing storage-class or type specifiers

How do I fix these?
In general, how do you get MFC and Standard C++ library constructs to co-exist?

Thanks in advance.
AYS.

chiuyan
May 24th, 1999, 11:25 AM
you need to qualify your string s; defintion. Use std::string s;

this won't make any of your warnings go away, but it will get rid of your errors.

MFC & STL stuff can coexist, but if you are already using the MFC, why would you want to use string over CString? CString is already available, and you are just going to increase your code size by adding the STL stuff.

--michael

May 24th, 1999, 12:05 PM
Thank you. The error did go away. However, there were warnings galore. Each file that included the doc header file produced the same warnings for a total of 120 of them. And this, when I just introduced a string definition.

As to your question, the reason that I used STL's string is skill-development. I'm currently reading Lippman's C++ primer and wanted to try out his examples. He uses plain-vanilla console applications. I wanted to try them out in Windows apps. Further, string was the first type I used. I intend to use other features of Standard C++ library as well and not all of them may have an equivalent in MFC. Will they?

It is noteworthy that in console apps, I didn't get any of these errors or warnings.

AYS

chiuyan
May 24th, 1999, 12:40 PM
you can turn down your error reporting to not report some of the not very important warinings, like unreferenced paramters and stuff (warning level on the C++ tab in project settings). You can also disable some of the warnings via the #pragma disable directives. I do not know why console apps do not generate the same warnings, but I guess VC just handles error checking differently in console apps. But, hey... they are just warnings ;-)

I am not overly familiar with the STL, but I do believe much of the STL functionality has been duplicated in the MFC. There is a CArray template (vector), there is a CList template (list), there is a CQueue template (queue), ...

--michael