#include <iostream>
#include <string>
#include <cstring>
class carl {
CString test(int a) {
CString aaa = new CString("Hallo");
return (aaa); }
}
I got the following error:
error C2146: syntax error : missing ';' before identifier 'test'
Why ?
Peter
Why are you using CString?
Use std::string.
--
"Come to think of it, there are already a million monkeys
on a million typewriters, and Usenet is NOTHING like
Shakespeare."
- Blair Houghton
<snip>
Microsoft's proprietary CString class is a Microsoft
Foundation Class library (MFC) class.
It is not defined in the standard headers <string> or
<cstring>, and (depending upon the version of VC
you are using) requires building the application with
wizards to add MFC support or delving into the
MS documentation on how to do it manually.
> I got the following error:
>
> error C2146: syntax error : missing ';' before identifier 'test'
Because the CString class is not defined.
As Jacques indicated, the best advice from this group
is to use std::string. Alternatively, check in a VC
newsgroup for advice on adding MFC to console
applications.
Because you've not included a definitions for CString anywhere.
Note that <cstring> is probably not what you think it is - it'd the
old C <string.h> header but in the std namespace.
If you want to use MFC CString class you'll need to include the
appropriate header and libraries for that, which I'm sorry I can't
help you with (and you'll be better asking in a microsoft/visual
c++ group for that)
Because you included the wrong header.
CString is an MFC class, it is not declared in the <cstring> header file.
You need <afx.h> or something (not sure exactly what, look it up), or
alternatively ditch the MFC CString class and try a proper string class like
std::string.
When you've fixed that, you have these problems (see comments)
class carl {
CString test(int a) {
CString aaa = new CString("Hallo"); // aaa should be a pointer
return (aaa); }
} // missing semi colon
john
Maybe someone can correct me if I'm wrong, but I think CString is an MFC
class. You need to create a project that supports MFC.
Booch
> If I tried to compile the following code for a win32 console application
>
> #include <iostream>
> #include <string>
> #include <cstring>
That's not the header file for the MFC CString class, but the C++ standard
library's wrapper around <string.h>. Which, again, is different from
<string> -- that one is the STL's std::string class.
> class carl {
>
You've got only private members in your class.
> CString test(int a) {
And right here, the compiler doesn't know the type CString.
> CString aaa = new CString("Hallo");
Here you're assigning a pointer to a nonpointer variable.
> return (aaa); }
> }
The semicolon at the end of the class declaration is missing.
> I got the following error:
>
> error C2146: syntax error : missing ';' before identifier 'test'
You'll have to check the MFC include directory to find the correct header
file for CString -- most probably you'll end up with <afx.h>.
Alternatively, you could change all references to CString to std::string.
Plus some strategically placed asterisks to resolve the pointer problem,
that should work as well. If the only MFC class you're going to use is
CString, then dropping MFC for the STL is IMHO worth a thought or two.
--
Christian Ullrich Registrierter Linux-User #125183
"Deliver."