Ticket #11141: test_noncopyable.cpp

File test_noncopyable.cpp, 525 bytes (added by Andreas Fenkart <afenkart@…>, 8 years ago)

class deriving boost::noncopyable and declaring copy constructor

Line 
1
2#include <iostream>
3
4#include <boost/noncopyable.hpp>
5
6class Foo : private boost::noncopyable
7{
8public:
9 Foo(const std::string name) : m_name(name) {
10 std::cout << "constructor\n";
11 }
12 Foo(const Foo &other) {
13 m_name = other.m_name + "'";
14 std::cout << "copy-constructor\n";
15 }
16 void print()
17 {
18 std::cout << "<" + m_name + ">\n";
19 }
20private:
21 int a;
22 std::string m_name;
23};
24
25int main()
26{
27 std::cout << "Hello World\n";
28 Foo f("f");
29 std::cout << "Now copy the thing\n";
30 Foo g(f);
31 g.print();
32}