PDA

View Full Version : Need some help with C++ classes (forward declaration etc.)



celemine1Gig
05-25-2009, 08:58 AM
Hi guys,

I have a problem here that nearly makes me go crazy. I'm sure I'm missing something (something big) and I don't really get it.

Here's the deal:

I have 3 classes (A,B,C).
Each class has a list of members (double values) and some functions to compute new values. Now for some computations, one class needs member-values from another class.
So, our professor told us to use forward declaration and pointers to solve that problem.

I did it like described in the following link and created a pointer in the class B header, to class A.

http://www-subatech.in2p3.fr/~photons/subatech/soft/carnac/CPP-INC-1.shtml

Now I thought that I could get the values from class A's members as follows:

If I have a pointer, just like in the linked example, named "fPtrA", can't I just use that in my class B member function as follows:

B::X = fPtrA->rtrn_member1() + B::Y

The "rtrn_member1()" function really is nothing else than the following simple code:


A::rtrn_member1() const {return member1;};


If I try to use this method, described above, in my class B member function, I immediately get an access violation.


So, where is my huge misunderstanding? Any hints are highly appreciated, as I'm starting to go nuts. :D

Thx in advance!

Ingmar :)

W1zzard
05-25-2009, 09:19 AM
did you initialize that pointer? if you use visual studio (you should), start learning how to use the debugger to step through your application and inspect values

show us more of your code

celemine1Gig
05-25-2009, 10:09 AM
Problem solved. Thx W1zzard. I really didn't initialize the pointers. I had initialized anything else, but totally forgot about the pointers and then wondered why I always got the same error. :am:

Did I already state that I love programming. :) ;) Well, at least if it comes to programming, I'm a total idiot. I think I :owned: myself, once again.