/*
* Test.h
*
* Created on: 03/12/2010
* Author: Mikaeru
*/
#ifndef TEST_H_
#define TEST_H_
#include <iostream>
using namespace std;
class Test {
private:
int j;
public:
Test(int i);
void print();
void setT(Test& t);
void setJ(int i);
int getJ();
};
Test t(1);
#endif /* TEST_H_ */
/*
* Test.cpp
*
* Created on: 03/12/2010
* Author: Mikaeru
*/
#include "Test.h"
Test::Test(int i) {
j = i;
}
void Test::print () {
cout << t.getJ() << endl;
}
void Test::setT(Test& test) {
t = test;
}
void Test::setJ(int i) {
j = i;
}
int Test::getJ() {
return j;
}
int main(int argc, char **argv) {
cout << "T" << endl;
Test t(3);
Test t2(1);
t2.setT(t);
t2.print();
t.setJ(5);
t2.print();
return 0;
}
And I want the second t2.print() to return 5, which should work because I'm passing t by reference, but for some reason it doesn't work. Why?


Sign In
Create Account


Back to top









