.net - 错误: “Expression must have class type” C++/C

不知道为什么不能编译。我在这里犯什么错误,我该如何解决?我正在尝试编译在示例中找到的这段代码,但是我的编译器必须具有比其严格的设置,或者可能是其他版本的编译器。该代码应只打开一个Windows窗体并显示一些文本。

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

public ref class MyForm : Form
{
public:

MyForm ()
    {
    Text = "Windows Forms Demo";
    }

void Main ()
    {
    Application.Run (gcnew MyForm());
    }

protected:
 void OnPaint (PaintEventArgs e)
    {

    e.Graphics.DrawString ("Hello, world", Font,
        gcnew SolidBrush (Color.Black), ClientRectangle);
    }   
}

最佳答案

您为override和访问方法编写了错误的语法。

 virtual void OnPaint(PaintEventArgs^ e) override
  {
    Form::OnPaint(e);
    e->Graphics->DrawString("Hello, world", gcnew System::Drawing::Font("Arial",20),  gcnew SolidBrush (Color::Black), ClientRectangle);
  }

并且不要使用void main()
[STAThreadAttribute]
int main()
{
     Application::Run(gcnew Form1());
     return 0;
}

关于.net - 错误: “Expression must have class type” C++/CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8739743/

相关文章:

c++ - `invalid initialization of non-const referen

flash - Flash编译器不允许覆盖

java - 错误包org.python.util不存在,使用ant进行编译

C++ - 清理后 Unresolved external symbol 错误

c++ - C++/LabVIEW互操作: error extracting data from L

ios - 导出版本时也出错,找不到iOS arm-apple-darwin9-as.exe

java - 即使定义了类和参数,Java也找不到符号错误?

java - Eclipse 拒绝我的公共(public) void init 方法

ios - Amazon IOS SDK : compiler warnings - ARC iss

java - 保存一个整数onClick,以便以后可以在android应用中调用它