473,729 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointers to partially specialized template methods, type confusion

I have a partially specialized templated class, which at one point needs
to pass pointers to some of its methods to another function. However, it
seems that my compiler (gcc) and me don't quite agree on the types for
the methods.

In the code below, the constructor to NLF2 (near the bottom) takes as
its last two arguments two function pointers of type void(*)(...), and
apparently &PR<2>::PR_i nit is of type void(PR<2>::*)( ...).

If I remove the partial specialization, and just leave a general
implementation of PR, it works.

Does anyone know what I'm missing here? (The NLF class comes from the
OPT++ library for numerical optimization)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
#include "OPT/NLF.h"
#include "OPT/NLP.h"

template< int TD >
class PR;

const int D = 2;
class PR<D>
{
public:
void init();

private:
void PR_function(int mode, int ndim,
const ColumnVector& x,
real& fx,
ColumnVector& gx,
SymmetricMatrix & Hx, int& result );
void PR_init(int dim, ColumnVector& parameters);
};

//template<int D>
void PR<D>::PR_funct ion(int mode, int ndim,
const ColumnVector& x,
real& fx,
ColumnVector& gx,
SymmetricMatrix & Hx, int& result) {}

//template<int D>
void PR<D>::PR_init( int dim, ColumnVector& parameters) {}

//template<int D>
void PR<D>::init()
{
NLF2 optimizer
(3, &PR<2>::PR_func tion, &PR<2>::PR_i nit );
//======== ERROR ON THE LINE ABOOVE =========
}
int main()
{
PR<2> pr;
pr.init();
return 0;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
Jul 22 '05 #1
1 1353
Martin Magnusson wrote in news:35e171fa.0 411230104.7cecc 7b2
@posting.google .com in comp.lang.c++:
In the code below, the constructor to NLF2 (near the bottom) takes as
its last two arguments two function pointers of type void(*)(...), and
apparently &PR<2>::PR_i nit is of type void(PR<2>::*)( ...).


The function expects normal functions, i.e. non-member or static-member
functions, you are passing non-static member function's.

Make the member's static or move them out of the class.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

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

Similar topics

2
2012
by: Thomas Matthews | last post by:
Hi, I would like to create a table (or vector) of pointers to templated functions. 1. How do I declare a typedef of a pointer to a templated function? For example, I have some functions that print out a type's name to an istream:
4
1857
by: Old Wolf | last post by:
I have a template class like this: template<typename T, int N> struct Foo { ........... }; which I have successfully specialized for some types, eg:
4
2282
by: Erik Wikström | last post by:
In school (no I will not ask you to do my schoolwork for me) we talked about policy-based design and got an assignment where we got the a code- fragment from a stack-implementation. The idea with the code was that if, when its destructor was called, it still contained any elements it would run 'delete' on them if they were pointers and do nothing if they were not. Our assignment was to reimplement the stack using policies so that the...
10
7557
by: danibe | last post by:
I never had any problems storing pointers in STL containers such std::vector and std::map. The benefit of storing pointers instead of the objects themselves is mainly saving memory resources and performance (STL containers hold *copies* of what's passed to them via the insert() method). However, I am not sure how to accomplish that using std::set. For various reasons, I cannot use vector or map in my application. But I would like to...
3
1967
by: a | last post by:
Hi, I'm trying to create a helper class that will allow me to use a pointer or reference to a class without knowing if it is a pointer or reference. Conceptual example: //****************** // class B has one public method f class B
92
5107
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers, but I just don't know. I don't like them because I don't trust them. I use new and delete on pure pointers instead. Do you use smart pointers?
8
2437
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A, typename B> class Base { public:
7
1928
by: mathieu | last post by:
Hi there, I know this is not possible in c++. So my question, how should I rewrite the following piece of code (without using a dummy class which template parameter could be use for partial specialization). template <typename TOut, typename TIn> void InverseRescaleFunction(TOut *out, const TIn *in, double intercept, double slope, size_t size) { ... }
5
3741
by: huili80 | last post by:
For example, like in the following, the part commented out was intended as partial spectialzation, but it would even compile. Is it even legal to partially specialize a nested template class inside another template class? template < typename T > struct A { template < typename U > struct B
0
8917
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
8761
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,...
1
9200
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
9142
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
6722
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
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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...
1
3238
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
2163
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.