错误:“表达式必须具有类类型” C++/CLI
不知道为什么这不能编译。我在这里犯了什么样的错误以及如何修复它?我正在尝试编译我在示例中找到的代码,但我的编译器必须具有比他们更严格的设置,或者可能是不同版本的编译器。该代码应该只打开一个窗口窗体并显示一些文本。
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);
}
}
Not sure why this won't compile. What sort of error am I making here and how do I fix it? I am trying to compile this code I found in an example but my compiler must have stricter settings than theirs or maybe a different version of compiler. The code should just open up a windows form and display some text.
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您为
覆盖
和访问方法编写了不正确的语法。并且不要使用
void main()
。You've written incorrect syntax to
override
and access methods.and don't use
void main()
.错误出在
Font
上,它是一个类。该调用需要一种字体,即Font
实例。The error is with
Font
, which is a class. The call expects a font, that is, aFont
instance.