Pointer to data member?

Started by
5 comments, last by flamewill 20 years, 8 months ago
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.
Advertisement
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]
I see. Thanks, Zipster.
Blt 'em Blittin' Blips.
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
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.
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.
Identifiers beginning with leading underscores are reserved for the implementation. A standard header file could #define _x to mean anything it wants.

This topic is closed to new replies.

Advertisement