[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
vi » CppError » gwbasic » Kenneth Thompson » talk:Windows » CppLinkingError » Pascal » CppKeyword » ATL » Open Source » CppMethod

(C++) Method

A class's member function.

In the example below, these are called setX and getX.

class Example
{
  public:
  void setX(const int& x)
  {
    mX = x;
  }
  int getX() const
  {
    return mX;
  }
  private:
  int mX;
};


Guideline from [1]

The standard requires that operators = () [] and -> must be methods. 
For all other functions:
IF the function is operator>> or operator<< for File I/O,
OR IF it needs type conversions on its leftmost argument,
OR IF it can be implemented using the class's public interface alone,
  Make it a non-member (and friend in the first two cases).
    IF it needs to behave virtually, 
      add a virtual member function to provide the virtual behaviour 
      and implement it in terms of that.
ELSE make it a member


Code links

References



last edited (November 15, 2006) by bilderbikkel, Number of views: 7366, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.