0

There is a function isInstruction() in my code (not mine) which is used for setting and getting a member with no problem. Now I added my own function for similar purpose state(). Like this:

struct foo { bool & isInstruction() { return isInst; // no problem } int & state() { return state; //ERROR } private: bool isInst; int state; }; 

I have no problem with the first function. But for the second one, I get

error: invalid initialization of reference of type ‘int&’ from expression of type ‘<unresolved overloaded function type>’ 

Then question is what is the difference between these two functions. Am I missing something?

1
  • Please show the full error message. Commented Jan 10, 2013 at 17:55

1 Answer 1

5

The difference is that the two entities (the member variable and the member function) are sharing the same name, state, which is what's causing the problem.

Try renaming one of them.

Sign up to request clarification or add additional context in comments.

1 Comment

I was 1ms away from hitting post.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.