#ifndef TEST_H
#define TEST_H
class test {
public:
int val;
int* pVal;
int k;
test(int x=40); //Constructeur par transtypage et par defaut
test(const test &other); //Constructeur par copie
int increment_static();
void toString();
void operator=(const test &source);
private:
int i;
};
#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(){
auto s = [this](){this->i++;};
return this->i;
}
void test::operator=(const test &source) {
this->val = source.val;
this->k = source.k;
this->i = source.i;
this->pVal = &this->val;
}
//Auteur : Raphael De Oliveira
#include <iostream>
#include "test.h"
using namespace std;
int main() {
test t1;
t1.toString();
cout<<t1.increment_static()<<endl;
cout<<t1.increment_static()<<endl;
cout<<t1.increment_static()<<endl;
cout<<t1.increment_static()<<endl;
return 0;
}
Add a code snippet to your website: www.paste.org