Oct 29, 2012 at 4:24pm
Can private class functions use private members without specifying in the function implementation?
Oct 29, 2012 at 5:37pm
Like this? Yes, private functions can use private members.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
class MyClass
{
public:
int SetAndPrintX(int i)
{
x = i;
print();
}
private:
int x;
void print()
{
std::cout << x;
}
};
int main()
{
MyClass c;
c.SetAndPrintX(3);
return 0;
}
|
3 |
Last edited on Oct 29, 2012 at 5:38pm