473,725 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with multiple parameter templates and function overloading

I have written the following very short template class in testclass.h:

template<typena me C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
};

template<typena me C,typename T>
T TestClass<C,T>: :testFunction(T dummy)
{
C bla;
return dummy;

}

So far it compilates fine.
Now i want to overload the testFunction:

template<typena me C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(do uble dummy);
};

template<typena me C,typename T>
T TestClass<C,T>: :testFunction(T dummy)
{
C bla;
return dummy;

}

/* now comes the problematic part */

template<typena me C>
double TestClass<C,dou ble>::testFunct ion(double dummy)
{
C bla;
return dummy;
}

I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFu nction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFu nction(double)'

If I remove the parameter C everything works fine of course.
Please can anybody help me.
I think its probably just a small problem.

Sep 12 '06 #1
1 2507

ny*****@hotmail .com wrote:
I have written the following very short template class in testclass.h:

template<typena me C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
};

template<typena me C,typename T>
T TestClass<C,T>: :testFunction(T dummy)
{
C bla;
return dummy;

}

So far it compilates fine.
Now i want to overload the testFunction:

template<typena me C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(do uble dummy);
};

template<typena me C,typename T>
T TestClass<C,T>: :testFunction(T dummy)
{
C bla;
return dummy;

}

/* now comes the problematic part */

template<typena me C>
double TestClass<C,dou ble>::testFunct ion(double dummy)
{
C bla;
return dummy;
}
Your testFunction is not a template function. I am not quite sure what
you are trying to do, but the bottom line is you have a template class.

So, if you want to have a specialized testfunction implementation for
double, then first specialize the template class TestClass for double
and then have an implementation for that.

Look up partial specialization (function templates cannot support them)
something like this...

template<typena me C>
class TestClass<C, double>
{
public:
double testFunction(do uble dummy);
};

template<typena me C>
double TestClass<C,dou ble>::testFunct ion(double dummy)
{
C bla;
return dummy;
}
>
I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFu nction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFu nction(double)'

If I remove the parameter C everything works fine of course.
Please can anybody help me.
I think its probably just a small problem.
Sep 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6479
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. Note that the overload is identical to the specialization except, of course, for the missing "template <>". I don't know if my questions will be a bit too broad or not, but I thought I'd give it shot... When is overloading preferable to...
7
2001
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
4
2402
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
16
16282
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
2
1599
by: recover | last post by:
#include <stdio.h> template<class T> class TpHello { public: int GetHash(){return 0;} protected: private: T a;
1
2804
by: Senthryl | last post by:
I just moved from Visual Basic to C++ and recently finished reading my book. However, I'm trying to implement something which has led me to writing the same thing many times, which I've learned is an indicator of poor design. I have a member function called GetInput of a class called UI. The function needs to accept all of the different built-in types as the same parameter. Therefore I decided to use overloading, but this requires...
6
391
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
7
2322
by: matthias.neubauer | last post by:
I have problems understanding how overloading of function templates works. Consider first the following code without any function templates ... int foo(const char *& c) { return 0; }
6
4546
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.