C ++/CLI表单,如何调用方法 [英] C++/CLI Forms, how to call a method

查看:86
本文介绍了C ++/CLI表单,如何调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Visual c ++ clr表单应用程序构建项目,并且向该项目添加了新表单,但是我无法使用此代码对其进行调用

例如:form2-> show();
或project_namespace :: form2 :: show();

I am building a project in visual c++ clr form application and i added a new form to the project but i can''t call it using this code

ex: form2->show();
or project_namespace::form2::show();

help?

推荐答案

您正在尝试在类上调用实例方法.类是类型,实例是对象.在类上仅调用静态方法和属性.在实例上调用静态方法和属性.区别在于:每个实例方法都隐含(不可见)"this"参数,该参数可以访问实例数据(以及其他实例方法和属性).您需要将一个对象声明为变量或使用gcnew创建一个对象,以具有一个实例来调用实例方法或属性.

我觉得在开始UI开发之前,您需要先回到基础知识.

-SA
You''re trying to call instance method on class. Class is a type, instance is an object. Only static methods and properties are called on classes; static methods and properties are called on instances. The difference is: each instance method has implied (invisible) "this" parameter which gives access to instance data (and hence other instance methods and properties). You need to declare an object as a variable or create an object with gcnew to have an instance to call instance methods or properties.

I feel you need to step back to basics before you get to UI development.

—SA


下面是两个有关如何创建form2类实例的示例.

Below are two examples on how to create an instance of your form2 class.

form2 ^myform = gcnew form2();
myform->Show();




or

(gcnew form2())->Show();


这篇关于C ++/CLI表单,如何调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆