language: C++11 (gcc-4.7.2)
date: 337 days 15 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
 
struct Foo
{
    void* address;
    bool testFlag;
    
    Foo ( ) : address(NULL), testFlag(false)
    {
        std::cout << "Foo default constructor called" << std::endl;
    }
    explicit Foo (bool Flag) : address(NULL), testFlag(Flag)
    {
        std::cout << "Foo (bool) constructor called" << std::endl;
    }
    explicit Foo (void* Pointer) : address(Pointer), testFlag(false)
    {
        std::cout << "Foo (void const*) constructor called" << std::endl;
    }
    Foo (void* Pointer, bool Flag) : address(Pointer), testFlag(Flag)
    {
        std::cout << "Foo (void*, bool) constructor called" << std::endl;
    }
};
 
int main(void)
{
    std::size_t* test = new std::size_t;
    
    Foo a (test);
    std::cout << a.address << ' ' << a.testFlag << std::endl;
    
    Foo b (false);
    std::cout << b.address << ' ' << b.testFlag << std::endl;
    
    Foo c (true);
    std::cout << c.address << ' ' << c.testFlag << std::endl;
    
    Foo d;
    std::cout << d.address << ' ' << d.testFlag << std::endl;
    
    Foo e (test, true);
    std::cout << e.address << ' ' << e.testFlag << std::endl;
    
    delete test;
}