Skip to main content
gamedev.net
🔒 Locked

Pointer to data member?

Started by flamewill Aug 8, 2003 at 1:10 AM 5 replies 350+ views
Original Post
flamewill
flamewill
According to ANSI C++, does a pointer to a data member need to be clarified by the namespace? For example:
class One
{
private:
  int _x;

public:
  int* getPx() { return &_x; }
};


class Two
{
private:
  int* _pY;

public:
  void setPy( int* pY ) { _pY = pY; }
};
Do I need to use One::int* instead of plain int* ? [edited by - flamewill on August 8, 2003 2:14:21 AM]
Blt 'em Blittin' Blips.
Zipster
Zipster
You'd only need to clarify the namespace if it's a custom type created within a class, such as an enumeration or nested class. Of course this includes if it was created in another namespace, in which case you'd need it also.

[edited by - Zipster on August 8, 2003 2:23:50 AM]
flamewill
flamewill
I see. Thanks, Zipster.
Blt 'em Blittin' Blips.
antareus
antareus
AFAIK (second post I''ve seen so far today with them) isn''t one underscore on variable names a big no-no by the standard?
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
flamewill
flamewill
quote:
Original post by antareus
AFAIK (second post I''ve seen so far today with them) isn''t one underscore on variable names a big no-no by the standard?

It is? I''m just a beginner who saw some books do it and thought it is a neat idea. If there is any particular reason the standard discourages it, I''d like to know please.
Blt 'em Blittin' Blips.
Zipster
Zipster
I forgot to mention, that also includes typedefs created within a class.

As for the naming, I believe it conflicts with something else. Not sure though.
Beer Hunter
Beer Hunter
Identifiers beginning with leading underscores are reserved for the implementation. A standard header file could #define _x to mean anything it wants.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.