vendredi 21 décembre 2018

C++ Pass class object instance as parameter to another class object instance from main()

I'm having issue on passing class object instance as parameter to another class object instance from main() function. Basically the problem is inside code below:

#include <something>
#include "another_thing"

class A
{
    void method1()
    {
        ;
    }

    void method2()
    {
        ;
    }
};

class B
{
    // Define an object of type class A
    A class_object;

    // Constructor
    B(A &passed_object)
    {
        class_object = passed_object;
    }

    void method1()
    {
        ;
    }

    void method2()
    {
        ;
    }
};

int main()
{
    A firstObject;
    B secondObject(firstObject);

    // Do something that changes A attributes;

    return 0;
}

The problem is that during main()'s execution some attributes of firstObject is changed but within passed_object inside class B I don't see this changes

Aucun commentaire:

Enregistrer un commentaire