# Invalid Use of Member (Did you forget the '&'?)

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have gotten far in my program that I'm making an am now stuck with this line of code:
if (Script.substr(Pos, GTAddress.length + 1) == GTAddress + ":")
My log says:
C:\CPP\PowerScript\Compiler.cpp:46: error: invalid use of member (did you forget the &' ?)

##### Share on other sites
Yeah, that worked out. If you can't figure out a problem, try the parentheses! Thanks.

##### Share on other sites
no. You need to learn the basics. Throwing symbols at bugs may work sometimes but it is a horrible, horrible, horrible, horrible way to code. Yes, all four "horribles" are needed. I strongly recommend that you purchase of "The C++ Programming Language" by Bjarne Stroustrup, the creator of C++. I also strongly recommend that you stop adapting example source code, as I suspect that is how you are teaching yourself.

##### Share on other sites
Now let's pretend you didn't have the internet and were without the friendly people on gamedev. So now we'll do a basic lesson on problem solving. So you're given a compiler error that you can't figure out, but you are told what line it's on. You've got a pretty long statement there, so you can't figure out exactly what the compiler is complaining about. So one way to tackle it is to break the statement down to smaller parts and see which part the compiler doesn't like. In this case you might try:

std::string sub = Script.substr(Pos, GTAddress.length + 1);
if (sub == GTAddress + ":")

Now the compiler error migrates up the line. So try to break that down further.

int len = GTAddress.length + 1;
std::string sub = Script.substr(Pos, len);

Compiler error migrates up a line again. Now you'd probably see for yourself what the problem was.

##### Share on other sites
Quote:
 Original post by GlakI also strongly recommend that you stop adapting example source code, as I suspect that is how you are teaching yourself.

For your information, I actually GOOGLED it first, second, without finding any help, I TRIED to fix the code. I didn't just throw a bunch of symbols at it, I messed around with it and figured out that it had to be something to do with the length member of the string, but the compiler told me that it had something to do with a ampersand, AND NOT PARENTHESES. I read PLENTY of sources to learn my coding, and I am still a newbie in training. I don't have the money to shell out for a new book every time someone recommends it to me.

And, SiCrane, thanks for the suggestion, as I will try that next time.

##### Share on other sites
Quote:
 Original post by orcfan32I have gotten far in my program that I'm making an am now stuck with this line of code:if (Script.substr(Pos, GTAddress.length + 1) == GTAddress + ":")My log says:C:\CPP\PowerScript\Compiler.cpp:46: error: invalid use of member (did you forget the &' ?)Not sure about this, and I never have read anything about having a & symbol.Script and GTAddress are strings.

GTAddress + ":" ? Does the object have operator+ defined?

If so, try parenthesis around it, so that the == doesn't take precidence in the order of operations. This is one of those situations where if (a&&b==c&&d) is interpreted by the compiler as if(a&&(b==c)&&d) when you probably meant if((a&&b)==(c&&d)).

1. 1
2. 2
Rutin
18
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 10
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633745
• Total Posts
3013667
×