user2778542
user2778542

Reputation: 31

Equality operator issue (C++)

I'm getting the error

no match for 'operator==' in 'MyNestedClassPointer->MyClass::MyNestedClass::NestedVar == s'

Where s is a reference to a string, and NestedVar is a pointer to a string. The offending line of code is an if statement comparing the two to see if they're identical.

if(thePointer->theVar == s)

I have no overloaded operators, but I don't think I should have a need for them, seeing as these are just string pointers we're dealing with. Now correct me if I'm wrong, since I'm more than a little rusty, but can't I do this?

Upvotes: 2

Views: 108

Answers (1)

smac89
smac89

Reputation: 43224

As one of the comments has mentioned, the correct syntax to compare a pointer to string object and a string object is by dereferencing the pointer.

Therefore in your code, it should be:

if( *thePointer->theVar == s )

Upvotes: 2

Related Questions