473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1208
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Douglas Peterson | last post by:
Take a look at this code, it looks funny as its written to be as short as possible: -- code -- struct Base { ~Base() { *((char*)0) = 0; } }; struct Derived : public Base
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
0
by: Arne Claus | last post by:
I've got a tricky problem here. I try to create an object-hierarchie, based on a template base class like template <class T> class Node { addChild(Node<T> *) =0; // the Node-Container wil be...
6
by: Jules | last post by:
I have the following code which isn't working as I expect it to: --- #include <iostream> using namespace std; class mystring { public: mystring (const char * src) { /* ... */ }
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
19
by: n.torrey.pines | last post by:
I have the following tree definition: template<typename T> struct tree { T first; vector<tree<T second; // branches }; which compiles successfully. What I'd like to do though is to use...
2
by: kasthurirangan.balaji | last post by:
Hello, template<class Base> class Derived : public Base { }; By using template, i understand the actual base type will be deduced at compile time. Moreover, class Derived will consist only...
4
by: suman.nandan | last post by:
Hi C++ Experts ! I have a little weird requirement. I have a base class, say B and lots of classes D1 .. Dn publicly derived from it. Over the course of development the number of derived...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.