Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

New GoF design pattern

Name: Anonymous 2014-04-29 4:31

CONSTIPATED ENCAPSULATION

#include <iostream>

class Anus
{
public:
Anus(int n=123):hax(&num) { num=n; }
void setNum(int n) { num=n; }
const int *const hax;
private:
int num;
} anus;

int main()
{
std::cout << *anus.hax << "\n";

anus.setNum(42);
std::cout << *anus.hax << "\n";

return 0;
}

Name: Anonymous 2014-04-29 16:59

>>10
Yes, but you shouldn't. The publicly exposed members should act as an interface only. By expose i to such treatment, it's behavior internal to it's class can never change (well, it can, but it won't be very pretty).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List