Hi all, I've been trying to create this header file that only contains this prototype struct so that I can use it across the different .cpp/.h files across my windows forms app. I found out that my original error was that I didn't have the 'ref' before the struct, but it still won't compile. I can create a string the exact same way in my main .cpp file, but not in this struct header for some reason. If I take the 'String ^ free_space;' line out, it compiles and runs perfectly fine. If anybody could offer some insight as to what I am doing wrong I would be very grateful.
Thanks,
Mike
1 2 3 4 5 6 7 8 9 10 11
#ifndef INFO_H
#define INFO_H
ref struct info
{
int mem_size;
int start_loc;
int used_space;
String ^ free_space;
};
#endif
Error Messages when compiling above code (Visual C++ 2010 express):
EMPL_INFO.h(9): error C2143: syntax error : missing ';' before '^'
EMPL_INFO.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
EMPL_INFO.h(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
There is no type String in C++. Symbol ^ is illegal in variable declaration in C++. Those are parts of C++/CLI: Microsoft language.
It seems that some parts of your project are compiled in C++ instead of C++/CLI. Make sure that when you create project you select CLR project. This might help: http://msdn.microsoft.com/en-us/library/ms235635.aspx
Ok, thanks a lot, I think I understand now, I will do that. Just to clarify: the System::String is not a C++ variable; the only true c++ string variable is in the <string> library of c++?