codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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; }
Private
[
?
]
Run code
Submit