Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

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

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

If you intended to correct an error in the post then please contact us.

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 `&' ?)
Not sure about this, and I never have read anything about having a & symbol. Script and GTAddress are strings.

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Glak
I 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 this post


Link to post
Share on other sites
Quote:
Original post by orcfan32
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 `&' ?)

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)).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!