Reputation: 1763
I've got a string pointer string* ifxPtr;
, what I'm trying to do is to set this pointer to point to the user input and then loop through each character of it.
string* ifxPtr;
void Expression::GetInfix(string data) // This method runs first and it's setting the pointer to point to previously passed user input
{
ifxPtr = &data;
ConvertToPostfix();
}
void Expression::ConvertToPostfix()
{
for (int i = 0; i < *ifxPtr->length; i++) // Here's the struggle, compiler is complaining about *ifxPtr with message Cannot apply binary '<' to 'int' and 'unassigned() const'
{
//Do something here
}
}
Upvotes: 2
Views: 46
Reputation: 36503
foo->
is shorthand for (*foo).
. Don't double up operators, also it should be length()
:
for (int i = 0; i < ifxPtr->length(); i++)
Also, be careful with that design, possibility of running into Undefined Behaviour with a simple mistake is big.
Upvotes: 1
Reputation: 239
if you use and *before it means using the value which is pointed by the pointer.
string s,*p; p=&s;
here *p.lenght() is same as s.length if you want to access through pointer you have to use it like this p->length().
Upvotes: 0
Reputation: 799
length
is a function and it should be length()
->
length()
is size_t
Here is what I would use:
int length = static_cast<int>((*ifxPtr).length());
Upvotes: 3