Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as C++ by registered user raphael ( 1 year ago )
//Auteur : Raphael De Oliveira
#include <iostream>
#include "test.h"
using namespace std;
template <class T>
void swapp(T &i ,T &j){
T temp(i);
i = j;
j=temp;
}
int main() {
int x=10;
int y=20;
cout<<"x = "<<x<<", y= "<<y<<endl;
swapp(x,y);
cout<<"x = "<<x<<", y= "<<y<<endl;
test t1;
test t2(50);
cout<<"t1 : ";
t1.toString();
cout<<"t2 : ";
t2.toString();
cout<<"Appelle de la fonction swap"<<endl;
swap(t1,t2);
cout<<"t1 : ";
t1.toString();
cout<<"t2 : ";
t2.toString();
return 0;
}
//--------------------------------------------------------------------------------------------------------------
#ifndef TEST_H
#define TEST_H
class test {
public:
int val;
int* pVal;
int k;
int i;
test(int x=40); //Constructeur par transtypage et par defaut
test(const test &other); //Constructeur par copie
static int increment_static();
void toString();
void operator=(const test &source);
};
#endif // TEST_H
//--------------------------------------------------------------------------------------------------------------
#include "test.h"
#include <iostream>
using namespace std;
test::test(int x) : val(x), pVal(&val), k(x), i(k+1) {}
void test::toString() {
cout << "val: " << val << ", *pVal: " << *pVal << ", pVal: " << pVal << endl;
}
test::test(const test &source){
this->val = source.val;
pVal = &val;
}
int test::increment_static(){
static int x=0;
x++;
return x;
}
void test::operator=(const test &source) {
this->val = source.val;
this->k = source.k;
this->i = source.i;
this->pVal = &this->val;
}
Revise this Paste