I am writing a class using 'composition' as follows -
class fibonacci
{
private:
FibonacciDynamic dy();
FibonacciRecursive re();
FibonacciSequential se();
int count;
public:
fibonacci(int a):count(a){};
void disp();
};
void fibonacci::disp()
{
if(count < 20)
{
se.fib();
}
else if(count < 50)
{
re.fib();
}
else
{
dy.display();
}
}
Here, FibonacciDynamic
, FibonacciRecursive
& FibonacciSequential
are classes declared in header files. Now, the main problem here is that while using se.fib()
, re.fib
& dy.fib()
functions it gives me error like
error C2228: left of '.fib' must have class/struct/union
Is there any other way to use composition approach here without getting above errors?
If not then is it possible to use them as friend classes & access their member functions in a member function of fibonacci
class?
Thanks.
FibonacciDynamic dy(); is declaration of method FibonacciDynamic fibonacci::dy();
you should remove parentheses to make it data member declaration:
...
FibonacciDynamic dy;
...