Class definition issue

Hi all,

I was hoping someone could help.

I have an issue with defining some classes in an application I am developing.
The classes hold a hierarchy and the child classes inherit functions from the parent class through polymorphism.
I have defined the parent class(Let's call this class A) and the child classes(B & C) in my menu driver using the #ifndef rule.
The problem is, I have another class(class D) which ideally could do with inheriting from either of the child classes(class B or class C) so I can create a vector of either class B or class C.

Is this possible? If I include the ifndef rule for class B and class C at the top of class D, it throws a hell of alot of errors complaining Class A is undefined. If I don't include the ifndef rule, (no includes at all) then it complains that class B is undeclared, the vector has an unknown size and there's no appropriate constructor available(I assume this is because it doesn't understand what class B is)

Any thoughts are much appreciated.

Thanks
Last edited on
I may have sorted it actually. There was no need to define class A, B or C in my menu driver.
Last edited on
Still got an issue.

Now in my menu driver I create a vector of class A. Inside class A it creates a vector of class B and you can add elements to the vector of class B using functions in class A(or just access it directly as I have below as it's currently public)
Accessing the vector of class A is fine and outputs as it should. But the vector of class B doesn't return what it should.
When I try and access a function (of an element) I get the output:
-1.85119e+062 (it should return a double).

My code is:
1
2
	classAVector.push_back(classA(custId,"Test","Test Addr","123","123",'m'));
	cout<<classAVector[0].getDetails();
- this works fine.
1
2
	classAVector[0].classBVector.push_back(classB(0,0,100,100));
	cout<<"Amount: "<<classAVector[0].classBVector[0].showBalance();
- returns -1.85119e+062

showBalance() =
1
2
3
4
	double showBalance()
	{
		return Account::showBalance();
	}



I'm getting so frustrated now, it feels like I take 1 step forward and 10 back.

Any help is appreciated, thanks very much
Last edited on
The issue was with the constructor, feel like I'm back to square 1
Topic archived. No new replies allowed.