为什么我不能在VC++ 2008中编译/运行这个非CLR程序?
怎么做?
#include <iostream>
namespace System
{
public class Console
{
public:
static void WriteLine(char str[])
{
std::cout<<str;
}
};
}
int main()
{
System::Console::WriteLine("This a non-CLR program!");
}
Run Code Online (Sandbox Code Playgroud)
Error 1 error C3381:
'System::Console' : assembly access specifiers are only
available in code compiled with a /clr option
e:\...\MyProgram.cpp 6
Run Code Online (Sandbox Code Playgroud)
小智 13
那不是非CLR C++程序.在适当的C++中,类不能是公共的(或私有的).你要:
namespace System
{
class Console
{
public:
static void WriteLine(char str[])
{
std::cout<<str;
}
};
}
Run Code Online (Sandbox Code Playgroud)
同样在C++中,字符文字是const,所以你的函数应该是:
static void WriteLine( const char * str)
Run Code Online (Sandbox Code Playgroud)
如果你想用一个作为参数调用它.