Quite new to C++ here, i'm trying to create a bi-directional One-To-Many association between two classes.
Here's what i achieved so far :
class_a.h
#ifndef CLASS_A_H
#define CLASS_A_H
class ClassB;
class ClassA {
public:
std::vector<ClassB *> Bs;
};
#endif
class_b.h
#ifndef CLASS_B_H
#define CLASS_B_H
class ClassA;
class ClassB {
public:
ClassA *classA;
std::string name;
};
#endif
But, when testing the following code, output is showing me test
.
Is b
being deleted correctly ? Should not this code returns a 139 error ?
main.cpp
auto *a = new ClassA();
auto *b = new ClassB();
b->classA = a;
b->name = "test";
delete b;
std::cout << b->name << std::endl;
Thanks !