[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppMethod
In the example below, these are called setX and getX.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
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
- 1) Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 20: Class mechanics.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
