[ create a new paste ] login | about

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

C++, pasted on Apr 12:
class  CNonCopyable
{
    private:
        CNonCopyable(CNonCopyable const &);
    public:
        explicit CNonCopyable(int) { }
};

// CNonCopyable arrayA[] = { CNonCopyable(0) }; // ERROR: copy constructor is inaccessable

struct CIndirectlyNonCopyable
        : public CNonCopyable
{
    explicit CIndirectlyNonCopyable(int x) : CNonCopyable(x) { }
};

CIndirectlyNonCopyable arrayB[] = { CIndirectlyNonCopyable(0) }; // OK

int main(int argc, char * argv[])
{
    return 0;
}


Output:
1
2
3
t.cpp: In copy constructor 'CIndirectlyNonCopyable::CIndirectlyNonCopyable(const CIndirectlyNonCopyable&)':
Line 4: error: 'CNonCopyable::CNonCopyable(const CNonCopyable&)' is private
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: