//Auteur : Raphael De Oliveira
#include <iostream>
#include "test.h"
using namespace std;
int main() {
    test obj1;
    test obj2 = obj1;

    obj1.toString();
    obj2.toString();

    obj1.val = 25;
    //*obj2.pVal = 30;
    obj1.toString();
    obj2.toString();

    int i(2);
    cout<<i<<endl;
    return 0;
}
//--------------------------------------------------------------------------------------------------------
#ifndef TEST_H
#define TEST_H


class test {
public:
    int val;
    int* pVal;

    test(int x=40);          //Constructeur par transtypage et par defaut
    test(const test &other); //Constructeur par copie
    void toString();
};

#endif // TEST_H
//--------------------------------------------------------------------------------------------------------
#include "test.h"
#include <iostream>
using namespace std;

test::test(int x)
{
    val=x;
    pVal = &x;
}

void test::toString() {
    cout << "val: " << val << ", *pVal: " << *pVal << ", pVal: " << pVal << endl;
}

test::test(const test &source){
    this->val = source.val;
    pVal = new int(source.val);
}

Add a code snippet to your website: www.paste.org