473,382 Members | 1,357 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,382 software developers and data experts.

Problem with multiple parameter templates and function overloading

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

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

template<typename 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<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(double dummy);
};

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

}

/* now comes the problematic part */

template<typename C>
double TestClass<C,double>::testFunction(double dummy)
{
C bla;
return dummy;
}

I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFunction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFunction(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 2489

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

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

template<typename 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<typename C,typename T>
class TestClass {
public:
TestClass() {};
~TestClass();
private:
T testFunction(T dummy);
/* definition of overloaded function */
double testFunction(double dummy);
};

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

}

/* now comes the problematic part */

template<typename C>
double TestClass<C,double>::testFunction(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<typename C>
class TestClass<C, double>
{
public:
double testFunction(double dummy);
};

template<typename C>
double TestClass<C,double>::testFunction(double dummy)
{
C bla;
return dummy;
}
>
I get the following compiler error:

behavior/testclass.h:47: error: no `double TestClass<C,
double>::testFunction(double)' member function declared in class `
TestClass<C, double>'
behavior/testclass.h:47: error: template definition of non-template
`double
TestClass<C, double>::testFunction(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
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. ...
7
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
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...
16
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
by: recover | last post by:
#include <stdio.h> template<class T> class TpHello { public: int GetHash(){return 0;} protected: private: T a;
1
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...
6
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.