template base class not fully expanded in some cases

Discussion in 'C++' started by henrik.jacobsson, May 21, 2008.

  1. Dear C++ gurus out there,

    Can anyone please tell me why A<string>::f(const pair<int,T>& _p) is
    not found in B<string>? (compiler version: g++ (GCC) 4.1.3 20070929
    (prerelease) (Ubuntu 4.1.2-16ubuntu2) )

    I get this:
    error: no matching function for call to
    'B<std::string>::f(std::pair<int, std::string>&)'
    note: candidates are: void B<T>::f(const T&) [with T = std::string]

    The data member is found correctly, however.

    Should I get a new compiler? Or am I missing something fundamental
    here? (I've already tried some const vs no const, inline etc... no
    luck)

    // Henrik J.

    ---

    #include <string>
    using namespace std;
    template<class T>
    class A {
    public:
    void f(const pair<int,T>& _p) {f(_p.second);} // just calling the
    virtual function
    virtual void f(const T&) = 0;
    virtual ~A(){}
    int m_data_member;
    };
    template<class T>
    class B : public A<T>
    {
    public:
    virtual void f(const T&) {}
    };
    int main(){
    pair<int,string> p(10,"hello");
    B<string> b;
    b.m_data_member = 10; // works
    b.f(p.second); // works
    b.f(p); // error, but why?
    }
     
    henrik.jacobsson, May 21, 2008
    #1
    1. Advertisements

  2. I think your problem has been discussed here:
    http://tinyurl.com/4ad3z

    Cheers,
    Zsolt
     
    Zsolt Dollenstein, May 21, 2008
    #2
    1. Advertisements

  3. Aha! I suppose the template made the error message less informative in
    this case. Templates have a tendency to make compiler errors quite
    indecipherable...

    Thanks a lot!

    // H
     
    henrik.jacobsson, May 21, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.