0
#include<iostream.h>
	 #include<conio.h>
	 class test
	 {
	  public:
		int data1;
		char data2;
		test()
		{
			cout<<"contrsuctor";
			data1=1;
			data2='a';
			}
		~test()
		{
			cout<<"destrucor";

			}
		void show()
		{
		cout<<"data1"<<data1;
		cout<<"data2"<<data2;

		}
		};
	 void main()
	 {
		test *ptr;
		test object1;
		ptr = &object1;
		cout<<"\npointer\n";
		ptr->show();
		delete ptr;
		getch();
		}

Edited by Narue: added code tags

Attachments
#include<iostream.h>
	 #include<conio.h>
	 class test
	 {
	  public:
		int data1;
		char data2;
		test()
		{
			cout<<"contrsuctor";
			data1=1;
			data2='a';
			}
		~test()
		{
			cout<<"distrucor";

			}
		void show()
		{
		cout<<"data1"<<data1;
		cout<<"data2"<<data2;

		}
		};
	 void main()
	 {
		test *ptr;
		test object1;
		ptr = &object1;
		cout<<"\npointer\n";
		ptr->show();
		delete ptr;
		getch();
		}
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Cross213
1

Firstly, what is the purpose of this program, secondly, I don't think it's very good style to do the actual methods inside the header file itself, and also int data1 and char data2 should be private members. It should look kinda like this:

class Test
{
 private:
   int data1;
   char data2;

 public:
   Test();
   ~Test();
   void show();
};

Edited by Cross213: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.