开发者

C++/CLI msvc++2010 class problem

开发者 https://www.devze.com 2023-04-01 17:35 出处:网络
I want to call the member function of a class created in my main f开发者_如何学JAVAunction, but I get some error, that I can\'t call a non-static member function. How to call the public member functio

I want to call the member function of a class created in my main f开发者_如何学JAVAunction, but I get some error, that I can't call a non-static member function. How to call the public member function "msg" of the "Form1"?

int main(array<System::String ^> ^args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    Application::Run(gcnew Form1());

    int test = 0;
    if (test>0) {
        Form1::msg("1");
    } else {
        Form1::msg("2");
    }
    return 0;
}


You need an instance handle of Form1. Obviously you shall store the lvalue of gcnew Form1() as the object to call msg on.

0

精彩评论

暂无评论...
验证码 换一张
取 消