#include <iostream>
#include <string>
usingnamespace std;
class Main{
public:
Main();
void Displaydetail(){ cout << "This is main class ! " << endl;}
};
class Second {
public:
Main themain;
void Display(){
cout << "This is the second class ! " << endl;
cout << "themain.Displaydetail() " << endl;
}
};
int main(){
Second theSecond;
Main theMain;
theSecond.Display();
system( "pause" );
return 0;
}
class Main{
public:
Main(){}
void Displaydetail(){ cout << "This is main class ! " << endl;}
};
class Second {
public:
Second(){}
void Display(){
cout << "This is the second class ! " << endl;
cout << "themain.Displaydetail() " << endl;
}
};
#include <iostream>
usingnamespace std;
class Main{
public:
Main(){}
void Displaydetail(){
cout << "This is main class ! " << endl;
}
};
class Second {
private:
Main themain;
public:
Second(Main &theMain)
{
themain = theMain;
}
void Display(){
cout << "This is the second class ! " << endl;
themain.Displaydetail();
}
};
int main(){
Main theMain;
Second theSecond(theMain);
theSecond.Display();
return 0;
}
//first class with the function
class_A
{
public:
void function_A();
}
//second class where you want to use the function
class_B
{
class_A A; //create an object of the first class
A.function_A(); //call the funtion "function_A()" of that object
}