473,399 Members | 2,858 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,399 software developers and data experts.

passing function template to class template

Ali
The code at the end of this message works just fine with M$ VS2005 but
with g++ 4.1.3 i get this:

node.cpp: In function ‘int main()’:
node.cpp:96: error: no matching function for call to
‘bnode<cxsc::interval>::bnode(cxsc::interval*, cxsc::interval*,
<unresolved overloaded function type>)’
node.cpp:38: note: candidates are: bnode<T>::bnode(const T*, const T*,
T (*)(const T&, const T&)) [with T = cxsc::interval]
node.cpp:34: note: bnode<T>::bnode() [with T =
cxsc::interval]
node.cpp:30: note: bnode<cxsc::interval>::bnode(const
bnode<cxsc::interval>&)
node.cpp:100: error: no matching function for call to
‘bnode<cxsc::interval>::bnode(cxsc::interval*, cxsc::interval*,
<unresolved overloaded function type>)’
node.cpp:38: note: candidates are: bnode<T>::bnode(const T*, const T*,
T (*)(const T&, const T&)) [with T = cxsc::interval]
node.cpp:34: note: bnode<T>::bnode() [with T =
cxsc::interval]
node.cpp:30: note: bnode<cxsc::interval>::bnode(const
bnode<cxsc::interval>&)

The crazy thing is that this

node<interval>* presult = new unode<interval(&x, exp);
interval r = presult->evaluate();

works with g++ 4.1.3 correctly. The class interval is from C-XSC here:
http://xsc.de .

Any help is appreciated.

-------------------------------------------------------------------------
[node.cpp]

#include "interval.hpp"
#include "imath.hpp"
using namespace cxsc;

#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifdef _DEBUG
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_NEW
#endif
#endif

template <class T>
class node {

public:

virtual const T evaluate() = 0;

virtual ~node();

};

template <class Tnode<T>::~node() {}

template <class T>
class bnode : public node<T{

public:

bnode<T() : node<T() {};

bnode<T(const T* const Arg1,
const T* const Arg2,
T Bop (const T&, const T&))

: node<T(), arg1(Arg1), arg2(Arg2), bop(Bop) { };

virtual const T evaluate();

~bnode<T>() {} ;

private:

const T* arg1;
const T* arg2;
T (*bop) (const T&, const T&);
};

template <class T>
const T bnode<T>::evaluate()
{
return (bop(*arg1, *arg2));
}

template <class T>
class unode : public node<T{

public:

unode<T() : node<T() {};

unode<T(const T* const Arg, T Uop (const T& ) )

: node<T(), arg(Arg), uop(Uop) { };

virtual const T evaluate();

~unode<T>() {} ;

private:

const T* arg;
T (*uop) (const T& );
};

template <class T>
const T unode<T>::evaluate()
{
return (uop(*arg));
}
int main() {

// exp(x + y*z)
interval x(2), y(3), z(0.5);

node<interval>* pyz = new bnode<interval(&y, &z, operator*);

interval yz = pyz->evaluate();

node<interval>* px_p_yz = new bnode<interval(&x, &yz, operator+);

interval x_p_yz = px_p_yz->evaluate();

node<interval>* presult = new unode<interval(&x_p_yz, exp);

interval r = presult->evaluate();

delete pyz;
delete px_p_yz;
delete presult;

#ifdef _MSC_VER
_CrtDumpMemoryLeaks();
#endif

return 0;

}
Aug 21 '08 #1
1 1894
Ali
The simplified code is at post 'function pointer'.
Aug 21 '08 #2

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
5
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
5
by: Active8 | last post by:
vector<double> signal; vector<double>::iterator iter; in_file.load_vector(signal); in_file.load_vector(signal.begin()); those calls give the compiler error: "could not deduce template...
4
by: Vijai Kalyan | last post by:
I was decomposing a task into different policies. Essentially, there is a general option obtained from a server and user options obtained from configuration variables. The two options are...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
0
by: Daniel G?rsch | last post by:
The following code works perfect in VS 2002 (compiled in a console project). Using VS 2003 the variable 'a' in the 'compute' function of the managed class 'M' is not correctly passed into this...
3
by: Dilip | last post by:
I am stuck with a syntactical issue and would appreciate some help: I have a class with a templated mem fn like so: class A { }; template<typename Ret, typename P1, Ret (A::*fp)(P1*)>...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...
0
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...

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.