[ create a new paste ] login | about

Link: http://codepad.org/4odTQaly    [ raw code | output | fork ]

C++, pasted on Jul 15:
#include <iostream>
using namespace std;

class Value {
	friend class ValueFactory;
	//friend Value* ValueFactory::New(int n) const;
public:
	int Get() const {
		return m_n;
	}
private:
	Value(int n) : m_n(n) {

	}
	Value(const Value&);
	void operator=(const Value&);
	int m_n;
};

class ValueFactory {
public:
	Value* New(int n) const {
		return new Value(n);
	}
};

#define ARRAY_SIZE(array) (sizeof (array) / sizeof *(array))

int main() {
	static const int VALUE[] = {
		1, 2, 4, 8,
	};
	static const int SIZE = ARRAY_SIZE(VALUE);

	ValueFactory factory;

	for (int i = 0; i < SIZE; ++i) {
		Value* value = factory.New(VALUE[i]);
		cout << value->Get() << ' ';
		delete value;
	}
	cout << endl;
}


Output:
1
1 2 4 8 


Create a new paste based on this one


Comments: