1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
const int size = 1;
template <class T>
class PASS_OBJECT;
template <class S>
class OBJECT
{
private:
S pass_object;
public:
OBJECT();
~OBJECT();
void PASS_OBJECT_TYPE_value(S pass_object, int x, int y);
void PASS_OBJECT_TYPE_reference(S &pass_object, int x, int y);
};
template <class S>
OBJECT<S>::OBJECT(){}
template <class S>
OBJECT<S>::~OBJECT(){}
template <class S>
void OBJECT<S>::PASS_OBJECT_TYPE_value(S pass_object, int x, int y)
{
std::cout<<pass_object.return_data( x, y)<<std::endl;
}
template <class S>
void OBJECT<S>::PASS_OBJECT_TYPE_reference(S &pass_object, int x, int y)
{
std::cout<<pass_object.return_data( x, y)<<std::endl;
}
template <class T>
class PASS_OBJECT
{
private:
static T data_array[size][size];
public:
PASS_OBJECT();
~PASS_OBJECT();
void insert_data( int data, int x, int y);
int return_data( int x, int y);
};
template <class T>
T PASS_OBJECT<T>::data_array[size][size];
template <class T>
PASS_OBJECT<T>::PASS_OBJECT()//constructor
{
for(int i = 0; i < size; i++)
for(int j = 0; j < size; j++)
this->data_array[i][j] = 0;
}
template <class T>
PASS_OBJECT<T>::~PASS_OBJECT(){}
template <class T>
void PASS_OBJECT<T>::insert_data( int data, int x, int y)
{
std::cout<<this->data_array[x][y]<<std::endl;
this->data_array[x][y] = data;
std::cout<<this->data_array[x][y]<<std::endl;
}
template <class T>
int PASS_OBJECT<T>::return_data( int x, int y)
{
std::cout<<this->data_array[x][y]<<std::endl;
return this->data_array[x][y];
}
int main()
{
PASS_OBJECT<int> pass_object;
pass_object.insert_data( 99, 0, 0);
std::cout<<"In main 1: "<<pass_object.return_data( 0, 0)<<std::endl;
OBJECT<PASS_OBJECT <int> > object;
std::cout<<"In main 2: "<<pass_object.return_data( 0, 0)<<std::endl;
object.PASS_OBJECT_TYPE_value( pass_object, 0, 0);
object.PASS_OBJECT_TYPE_reference( pass_object, 0, 0);
return 0;
}
|