jump to navigation

Request member non-class type… C++ October 4, 2006

Posted by Matt in Uncategorized.
trackback

For those of you whom programm in C++, I have a little tip whne working with calsses. If you get an erroer that looks like  this:

“Request for member”A” in “B” is of non-class type ”C”

Where A, B, and C ,may differ as to your actual code.

Whats happening(as far as I can tell…) is your calling things that don’t exist. We can only call things that exist….

Example(Plundered Geneously from below, so people strolling in don’t have to parse hundreds of comments)

In OBJECTS,

CObj Obj();//<–This the problem code.

If the CObj constructer has no parameters, It has no clue how to make such a thing, so it throws an error the nex t time you call for it. 

If your making something without parameters, do it thusly.(Maybe. Try it at least…)

 CObj Obj();//Better!

And that Might resolve the issue

In LINKED LISTS and POINTERS

float x = P.coord[0];//Problem Line

float x = P->coord[0];//Fixed.

I’m a bit away from Tech, so I openly admit to Bafflement on issues with Link Lists, Pointers, and the like.  i found this solutioon below and fixed it my self, apparently. But I’m not sure what it all means.

And for you late comers, for a period of MONTHS, this comment was naught but

For those of you whom programm in C++, I have a little tip whne working with calsses. If you get an erroer that looks like  this:

“Request for member”A” in “B” is of

Its a bit better now.

Advertisement

Comments»

1. Matt - October 17, 2006

Hello?

2. dan - November 5, 2006

…and the rest of what you were saying is…?

3. time - February 21, 2007

what you wanted to explain could be my problem i have now…

4. Matt - March 5, 2007

I honestly have no Idea of what I was saying. If you have any questions, definitly ask.

5. jimbo - April 7, 2007

Maybe he had a heart attack while typing

6. shawn - April 29, 2007

I’m getting this error:

request for member ‘coord’ in ‘P’, which is of non-class type ‘const attr_point*’

here’s the code that likely pertains:
struct attr_point{
static const int START = 4;
static const int CONSTANT = 4;
static const int MAX = 24;

float coord[MAX];
};

int draw_bezier_curve(const attr_point P [], int degree)
{
float x = P.coord[0];

return 0;
}

7. Matt - April 29, 2007

try using a -> instead of a .

float x = P->coord[0];, not float x = P.coord[0];

8. Another guy - May 2, 2007

Thank you

9. long john - April 1, 2008

dude (matt), were you drunk when you tried to post this?
your comment helped me, so thanks anyway

10. hlina - September 26, 2008

this may also occur when you call some method Met() of some object Obj declared as:

CObj Obj(); //bad definition

Obj.Met(); //raised error

if a constructor of the CObj object has no parameters, you should NOT use brackets in Obj declaration, write it rather as:

CObj Obj;

Obj.Met();

Note: tested on MinGW

11. Izabela - September 29, 2008

this may also occur when you call non-const method on const object.
In any case your topic has helped me)))).

12. fabo - April 2, 2009

in my case:
if your constructor does not take any arguments, don’t call the constructor function with brackets:

class myObject {
public: myObject(); ~myObject(); void doSomething();
};

myObject a();
a.doSomething();

– will raise an error on a.doSomething() line (for some reason). but what you need to change is the line:

myObject a;

13. oakus - April 28, 2009

the reason is, that
CObj Obj();
is declaration of function with no arguments returning object CObj
while
CObj Obj;
is creating of object of type CObj and calling its deafault constructor

14. Sadarax - April 30, 2009

About the -> versus the . operators, this is my understanding:

The ‘->’ operator automatically dereferences pointers, whether on the current object or its own private members.

The ‘.’ operator does not dereference, and thus the compiler cannot syntactically reach the desired method/member.

Structs frequently use the ‘->’ more than the ‘.’.

The dot operator can be used for dereferencing, but it is more work (and messy). For example, to set the value of x on the object p_ptr we have to do this:
(*p_ptr).x=0×8001010
instead of
p_ptr->x=0×8001010

15. Muftobration - September 9, 2009

CObj Obj();//<–This the problem code.

CObj Obj();//Better!

Those two lines look the same to me. Did you mean to omit the parenthesis from the second line?

Tetsuro - January 28, 2011

what he tried to say is use Values to inicialize it

Tetsuro - January 28, 2011

CObj Obj(type value,type value); // better

16. Gianks - January 17, 2010

Hey Matt, what about an Aspirine? eheh! Thanks anyway, you solved my problem!!!

17. angela - April 27, 2010

great! very useful!
thank you very much!

18. meh - May 3, 2011

meh

19. meh - May 3, 2011

meh2

20. meh - May 14, 2011

meh3

21. meh - June 7, 2011

meh4

22. Ivan - July 4, 2011

Thanks :)
But the strings
CObj Obj();//<–This the problem code.

CObj Obj();//Better!

should fix.

Ivan - July 4, 2011

Oh… I forgot… There is one else way of resolving this problem:
* i = new ();
i->method();

In my opinion declaration without brackets looks a little bit clumsy.
P. S. Sorry for my English if I make a mistake.

23. tang - September 8, 2011

Hi guy,

You make a mistake in your blog.

CObj Obj();//Better!
SHOULD be changed to
CObj Obj;//Better!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.