Fred Hui
Fred Hui

Reputation: 31

Effective C++ Item 43 Know how to access names in templatized base classes

In Item 43 of the book, it is said that the code below will not compile. My understanding is that, compilation error occurs when the method LoggingMsgSender::sendClearMsg is instaniated.

However, for the three compilers (VC 2005, gcc 4.4.1, and one for embeded device) I have tried. None of them show any compilation error.

Are there any compiler which can show the error as mentioned in the book? Any suggestions are welcome. Thank you for your help.

(I have found a potential compiler bug in VC 2005 in my source related to this kind of template base-class function call, that's why I want to the compilation error. That's a long story...)

class CompanyX
{
public:
    void sendClearText(){};
};

typedef int MsgInfo;

template<typename Company>
class MsgSender {
public:
    void sendClear(const MsgInfo&)
    {
        Company c;
        c.sendClearText();
    }
};


template<typename Company>
class LoggingMsgSender : public MsgSender<Company> {
public:
    void sendClearMsg(const MsgInfo& info)
    {
        sendClear( info );   // ERROR : will not compile despite clearly being in base class.
    }
};


int main()
{
    LoggingMsgSender<CompanyX> sender;
    sender.sendClearMsg(1); // specialization of the method!!!
}

Upvotes: 1

Views: 287

Answers (1)

ForEveR
ForEveR

Reputation: 55897

http://liveworkspace.org/code/273c71cd53111dd8c6aaa54e64c53548 for example. get an error. in this case in function sendClearMsg we should use this->sendClear(info); compiler is gcc 4.7.1. And so, now is 2012 year, why you use old compilers?

Upvotes: 2

Related Questions