473,783 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::in terval>::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::int erval>::bnode(c onst
bnode<cxsc::int erval>&)
node.cpp:100: error: no matching function for call to
‘bnode<cxsc::in terval>::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::int erval>::bnode(c onst
bnode<cxsc::int erval>&)

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.h pp"
#include "imath.hpp"
using namespace cxsc;

#ifdef _MSC_VER
#define _CRTDBG_MAP_ALL OC
#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>::evalu ate()
{
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>::evalu ate()
{
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
_CrtDumpMemoryL eaks();
#endif

return 0;

}
Aug 21 '08 #1
1 1918
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
10181
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 code... TCHAR myArray; DoStuff(myArray);
5
5304
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 adsq::QInitialise<struct adsq::Data>(struct adsq::Head<struct adsq::Data> *)" -----------adsq.h file
9
4806
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 am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
5
1971
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 argument for 'T'" the infile object is a non-template class with a template function
4
4259
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 complementary to one another. So I proceeded to decompose the tasks that deal with user options into two functions. Each of the functions do something and towards the end they do supplementary tasks that depend on the server option. The whole things...
39
7664
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 indicate: a) That I don't know enough b) Passing arguments by ref is bad
0
972
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 function. Actually using the debugger shows that the copy constructor of class 'A' is called correctly, but nevertheless the variable 'a' in the 'compute' function is not initilized, that is 'a.i' has random values. Additionally starting the...
3
2055
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*)> void A::somefunc()
18
2879
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 write an ordinary differential equation class that would solve a general equation in the form: dx/dt = f(x,t). The ode class shouldn't know anything about f, except how to call it.
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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
10081
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
9946
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...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
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.