2 text box1,2
2 button1,2
i have class person {have get, set (string ,int)}
and i want to declare
person p;
to see it in both two push button1,2
my problem is i declare
person p; inside buttons when buttons end
p.~person();is called
so i cant save value
and when i call p.get i get initial value
Expand|Select|Wrap|Line Numbers
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
- {person p;
- //string str;
- stringstr(constchar*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(textBox1->Text).ToPointer();
- p.set( str,int ::Parse(textBox2->Text));
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
- {person p;
- string str;
- int ag;
- p.get(str,ag);
Expand|Select|Wrap|Line Numbers
- class person
- {
- public:
- person();// create initial value
- ~person();//descon
- void set(string z,int a);//set value
- void get(string &z,int &a);//get value
- private:
- string name;
- int age ;
- };
person cpp
Expand|Select|Wrap|Line Numbers
- #include "StdAfx.h"
- #include "person.h"
- #include "stdafx.h"
- using namespace std;
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- person::person()
- {name="null";
- age=-1;
- }
- person::~person()
- {
- }
- void person::set(string z, int a)
- {name=z;
- age= a;
- }
- void person::get(string &z, int &a)
- {z =name;
- a=age;
- }