template base class not fully expanded in some cases

H

henrik.jacobsson

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?
}
 
Z

Zsolt Dollenstein

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 think your problem has been discussed here:
http://tinyurl.com/4ad3z

Cheers,
Zsolt
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?
}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top