In my class C, there is a pointer (var_a) to a class A, so in the destructor of C, I write "delete var_a". In vscode, the code works but doesn't stop automatically after the end of the main. Also, the line where var_a is deleted, is highlighted in yellow. The debug console print :
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
The hpp :
#ifndef DEF_TEST4
#define DEF_TEST4
#include <iostream>
#include <string>
class A
{ public:
A();
A(A const& copy_a);
virtual std::string printer();
protected:
std::string var;
};
class B : public A
{
public:
B();
B(B const& copy_b);
virtual std::string printer();
protected:
std::string var;
};
class C
{
public:
C(A* a);
~C();
virtual A* get_a();
protected:
A* var_a;
};
#endif
The cpp:
#include "test4.hpp"
A::A() : var("a")
{}
B::B() : var("b")
{}
A::A(A const& copy_a) : var(copy_a.var)
{}
B::B(B const& copy_b) : var(copy_b.var)
{}
std::string A::printer()
{
return var;
}
std::string B::printer()
{
return var;
}
C::C(A* a) : var_a(a)
{}
C::~C()
{
delete var_a;
}
A* C::get_a()
{
return var_a;
}
The main cpp :
#include "test4.hpp"
#include "test4.cpp"
#include <typeinfo>
int main()
{
A ca;
B cb;
B cb2(cb);
C cc(&ca);
C cc2(&cb);
std::cout << ca.printer() << std::endl;
std::cout << cb.printer() << std::endl;
std::cout << cb2.printer() << std::endl;
std::cout << cb2.A::printer() << std::endl;
std::cout << cc.get_a()->printer() << std::endl;
std::cout << cc2.get_a()->printer() << std::endl;
std::cout << "type cc2.get_a() : " << &typeid(cc2.get_a()) << std::endl;
std::cout << "type ca : " << &typeid(ca) << std::endl;
std::cout << "type cb : " << &typeid(cb) << std::endl;
cc.~C();
}
I suppose that there is a problem, but what? Sorry for the possible bad english, it's not my mother tongue. Thanks for your help.