error: insufficient contextual information to determine type

S

Squid Seven

I have created a class that contains an instance of a second class.
When i try to call a member function of the instance of the second class
from a member function of the containing class, I get the following
error message:

Insufficient contextual information to determine type.

I have generated the simplest sample I could come up with that
duplicates this error, and it is attached below. I am fairly new to
programming and hope that I am not wasting anyone's time with this, but
I have been searching the net and my reference texts for the past three
hours trying to figure it out and am completely frustrated. It must
have something to do with the second class being user defined, because
if I substitute a string object I have no problem manipulating it.
Please help!

Sample code:

#include <iostream>

using std::cout;

class FirstClass {

public:
FirstClass();
void setFirstClassValue( int );

private:
int firstClassValue;
};

FirstClass::FirstClass()
{
firstClassValue = 7;
}

void FirstClass::setFirstClassValue( int newValue )
{
firstClassValue = newValue;
}

class SecondClass {

public:
SecondClass();

private:
FirstClass instanceOfFirstClass();
};

SecondClass::SecondClass()
{
instanceOfFirstClass.setFirstClassValue( 10 ); //The problem line

};


main()
{
SecondClass instanceOfSecondClass();

Return 0;
}
 
P

Phil Staite

Squid said:
private:
FirstClass instanceOfFirstClass();

This doesn't do what you think it does. This declares a private member
function called instanceOfFirstClass that takes no arguments and returns
(by value) a FirstClass object. I think what you probably want here is:


private:
FirstClass instanceOfFirstClass;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top