470,815 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

template base class not fully expanded in some cases

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,stringp(10,"hello");
B<stringb;
b.m_data_member = 10; // works
b.f(p.second); // works
b.f(p); // error, but why?
}
Jun 27 '08 #1
2 1117
On Wed, 21 May 2008 07:22:31 -0700 (PDT)
"he**************@gmail.com" <he**************@gmail.comwrote:
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,stringp(10,"hello");
B<stringb;
b.m_data_member = 10; // works
b.f(p.second); // works
b.f(p); // error, but why?
}
Jun 27 '08 #2
See the FAQ item titled "What's the meaning of, Warning: Derived::f(char) hides
Base::f(double)", current available at, among other places, <url:http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9>.
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
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Douglas Peterson | last post: by
reply views Thread by Arne Claus | last post: by
2 posts views Thread by Greg Buchholz | last post: by
19 posts views Thread by n.torrey.pines | last post: by
2 posts views Thread by kasthurirangan.balaji | last post: by
4 posts views Thread by suman.nandan | last post: by
32 posts views Thread by Stephen Horne | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.