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:air<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?
}
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:air<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?
}