# Problems dereferencing and grabbing from a class

## Recommended Posts

Hey guys, it has been quite a while since I've posted a question, and I am having troubles getting the -> operator to work. It's probably something really dumb that I missed but here's what I need to do. I have in a class
char** CurrText;
char** CurrName;
int* TextX, *TextY;
int* NameX, *NameY;

These are in the MainRenderer Class, which is in the MainView class, which I will use to pass them by. And I am trying to pass them into function --
void setCurrText(char* str1, int x1, int y1, char* str2, int x2, int y2);

Like this-
setCurrText(MainView.MainRenderer->CurrName, MainView.MainRenderer->NameX,
MainView.MainRenderer->NameY, MainView.MainRenderer->CurrText,
MainView.MainRenderer->TextX, MainView.MainRenderer->TextY);

The compiler is throwing this error
base operand of '->' has non-pointer type 'Renderer'

I'm not sure on what this means, but I know it's not working. Could someone help me please?

##### Share on other sites
Show the decleration of whatever MainView's class is. It's hard to tell if your error is that you think a decleration is an instance or if you decalared it as a non-pointer but think it's a pointer.

-me

##### Share on other sites
setCurrText(MainView.MainRenderer.CurrName, MainView.MainRenderer.NameX,            MainView.MainRenderer.NameY, MainView.MainRenderer.CurrText,            MainView.MainRenderer.TextX, MainView.MainRenderer.TextY);

The -> is used when you have a pointer to a class not a built-in data type.

CMainView* pMainView = &MainView;pMainView->MainRenderer.CurrName... etc...

In your setCurrText call, the MainRenderer would have to be a pointer for that dereference to work.

Happy coding!

##### Share on other sites
Aha! Thank you!

PS I knew it was something stupid.

##### Share on other sites
Compilers don't "throw" errors; they report them.

The error reads: "base operand of '->' has non-pointer type 'Renderer'"

The "base operand" of -> is the thing on the left-hand side.

x->y is equivalent to (*(x)).y, where 'x' is everything in the chain beforehand.

In your case, x is MainView.MainRenderer, which is our base operand.

The type of the MainRenderer member of the MainView object is 'Renderer', according to the compiler. This is a "non-pointer type", because, well, it's not a pointer type. :) So the error means exactly what it says: the base operand has a non-pointer type, and here's what the type actually is. And it's an error because we're trying to get (*(x)).y, but we can't do the *(x) part when (x) isn't a pointer.

You want to dereference the CurrText, etc., not the MainRenderer, as noted.

However, the kinds of pointer use you illustrate there suggest to me that you are likely to be doing a lot of other things very wrong as well. Used properly, pointers are actually quite rare in modern C++. The combination of 'char*' with a variable with 'text' in the name is also a very big warning signal :)

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627657
• Total Posts
2978471

• 10
• 12
• 22
• 13
• 33