Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Class cross deletion

Avatar of Rok-Kralj
Rok-KraljFlag for Slovenia asked on
C++
23 Comments1 Solution466 ViewsLast Modified:
Consider the code below. I get the folowing error and I know why i get it. The question is, how can i avoid it with the similar functionality and without memory leaks?

g++ -Wall -o "test" "test.cpp" -O3 -funroll-loops
test.cpp: In destructor ‘a::~a()’:
test.cpp:10: warning: possible problem detected in invocation of delete operator:
test.cpp:10: warning: invalid use of incomplete type ‘struct b’
test.cpp:1: warning: forward declaration of ‘struct b’
test.cpp:10: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
Compilation finished successfully.

struct b;

struct a {
	b* ptr;
	
	a() {
		this->ptr=0;
	}
	~a() {
		delete this->ptr;
	}
};

struct b {
	a* ptr;
	
	b() {
		this->ptr=0;
	}
	~b() {
		delete this->ptr;
	}
};
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffricSoftware Engineering and Matlab Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 23 Comments.
See Answers