开发者

Make a class in C++ form application global

I find myself stumnped by what should be a simple problem. How do you make a class (created in a seperate file) have global scope when using forms in Microsoft C++. I can declare, initalize, and use it in a textbox leave or keypress function but when I move to a button it is out of scope (the button and textbox have global scope, but I just am stumped by how they do it). The pro开发者_如何学Pythonblem is to make a clone of the class (object) and to do that it is advantageous to have the global scope. I realize this is homework, and I am not asking for code, just point me in the right direction. Thanks DJ

using namespace Circle; 

form1 code textBox1->Keypress(...) { 

Circle^ C = gcnew Circle(Convert.ToDouble(textBox1->Text)); // write to labels on form the rad, area, and circum 
} 
button1->click(...) { // I want to make a clone of the instance above 

Circle^ C = gcnew Circle(Convert.ToDouble(textBox1->Text)); 
Circle^ CL = C->Clone(C->Radius); // Clone and radius are members of the class Circle 

} 

The above code works because I created C again.

The following code will not work:

button1->clicked(...) 

{ 

Circle CL = C->Clone(C->Radius); 

}


You need to use a header file and include that in your Form class. Keep in mind if the class does not need to be in the same namespace then you have to define using namespace your_namespace; in your form class as well or refer to your class object by your_namespace::class

See also: Introduction to C++

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜