Jump to content
  • Advertisement
Sign in to follow this  

Problems dereferencing and grabbing from a class

This topic is 4380 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

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

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


Share this post

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

Link to post
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 :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!