#include <iostream>
using namespace std;
class a{
int x; //private
public:
int getX(){return x;}
void setX(int a){
x = a;
}
};
int main(){
a obj;
obj.setX(10);//Functions are called over objects.
cout << "x = " << obj.getX() << endl;
return 0;
}
Another way
//-----------------------------Seperating in 3 files-----------------------------------------------------------------
//test.h
class a{
int x; //private
public:
int getX(){return x;}
void setX(int a){
x = a;
}
void copyConstructor(a &obj);
};
//-----------------------------------
//test.cpp
#include "test.h"
void a::copyConstructor(a &obj){
x = obj.getX();
}
//----------------------------------
//Main.cpp
#include <iostream>
#include "test.h"
using namespace std;
int main(){
a obj;
obj.setX(10);//Functions are called over objects.
cout << "x = " << obj.getX() << endl;
a obj1;
obj1.copyConstructor(obj);
cout << "obj1 = " << obj1.getX() << endl;
return 0;
}
very de-tailed programe . easy to understand ..thanks!!Daniyal Ahmad Butt
ReplyDeleteYou're welcome +Daniyal Ahmad Butt.
ReplyDelete