help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a weird compiling error in gcc4.2.2


From: kuangye
Subject: a weird compiling error in gcc4.2.2
Date: Thu, 21 Aug 2008 19:14:08 -0700 (PDT)
User-agent: G2/1.0

#include <iostream>
using namespace std;
class TSB
{
//-----key point 1
        friend TSB fnbase();
//-----key point 2
protected:
        TSB()
        {
                cout<<"TSB()"<<endl;
        }
//-----key point 3
        TSB(const TSB&other)
        {
                cout<<"TSB(const TSB&other)"<<endl;
        }
public:
        ~TSB()
        {
                cout<<"~TSB()"<<endl;
        }
};

class TS:public TSB
{
public:
        TS()
        {
                cout<<"TS()"<<endl;
        }
//-----key point 4
        TS(const TSB&other)
        {
                cout<<"TS(const TSB&other)"<<endl;
        }

        TS(const TS&other)
        {
                cout<<"TS(const TS&other)"<<endl;
        }
        ~TS()
        {
                cout<<"~TS()"<<endl;
        }
};


TSB fnbase()
{
        return TSB();
}

TS fn()
{
//in gcc 4.2.2, the following statement will cause compiling error.
/*
1.cpp: In function 'TS fn()':
1.cpp:12: error: 'TSB::TSB(const TSB&)' is protected
1.cpp:52: error: within this context
*/
//But it works in gcc 3.4.
//---
        return TS(fnbase());

//It seems that in gcc4.2.2.  "return TS(fnbase());" will convert to
the following two statement
//..
        //TSB ret = fnbase();
        //return TS(ret);
}



int main()
{
        TS ts = fn();
        return 0;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]