MattDella
MattDella

Reputation: 15

Compilation error when declaring derived object as a private member in a class

My compiler is complaining that my declaration of an object as a private member of a different class (shown below) gives me this error:

private:

   ForwardStrategy::ForwardStrategy* forwardStrategy;

   ForwardToStrategy::ForwardToStrategy* forwardToStrategy;

/home/ics45c/projects/p4/src/Person.hpp:45:19: error: qualified reference to 'ForwardStrategy' is a constructor name rather than a type wherever a constructor can be declared ForwardStrategy::ForwardStrategy* forwardStrategy; ^ /home/ics45c/projects/p4/src/Person.hpp:47:21: error: qualified reference to 'ForwardToStrategy' is a constructor name rather than a type wherever a constructor can be declared ForwardToStrategy::ForwardToStrategy* forwardToStrategy; ^

2 errors generated.

So it looks like the compiler believes I'm referring to the constructor rather than the type, but I'm not sure how to correct the issue...

Sorry about the awful formatting... I'm not really sure how to do this correctly, but thanks in advance!

Upvotes: 1

Views: 1983

Answers (1)

Taha
Taha

Reputation: 2316

Just change it to :

private:

ForwardStrategy* forwardStrategy;

ForwardToStrategy* forwardToStrategy;

because the way it's written in your question means you are trying to access a member (which is the constructor function) of this class not defining an instance of it.

Upvotes: 1

Related Questions