LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2011, 04:44 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
C++: How to put a pointer to a function, in a class template, without typedef'ing it?


Code:
#include <iostream>

template <class MyDummyClass, typename  (MyDummyClass ::*Method)(Parameter), typename Parameter>
class happy
{
     public:
	  happy () {}
};

int main () {}
Code:
anisha@linux-uitj:~> g++ help.cpp -Wall
help.cpp:3: error: expected nested-name-specifier before ‘(’ token
help.cpp:3: error: expected ‘>’ before ‘(’ token
 
Old 03-05-2011, 06:18 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I think your two related threads would have been easier to answer if they were one thread. So I will add my answer for your question in this thread into my answer in the other thread:
http://www.linuxquestions.org/questi...6/#post4279709
 
Old 03-05-2011, 07:13 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
don't avoid typedefs they are very good style.
look at the X windows headers as a good example.
 
Old 03-05-2011, 07:52 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You're using a value-based template parameter, not a type-based parameter; therefore, it won't compile with typename. Also, Parameter is undefined; if you move it to the second position and specify a return type for Method, it compiles. The problem is, you can't infer Parameter.
Code:
template <class MyDummyClass, typename Parameter, void (MyDummyClass::*Method)(Parameter)>
class happy
{
     public:
          happy () {}
};


struct unhappy
{
	void function(int) {}
};


static happy <unhappy, int, &unhappy::function> data;
Kevin Barry

Last edited by ta0kira; 03-05-2011 at 08:01 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++: template member function used in a different templated class matze Programming 5 04-10-2008 09:26 AM
"undefined reference" to a template class function btb Programming 3 08-25-2005 05:02 PM
Template class with a template member... Nicholas Bishop Programming 3 02-21-2005 08:27 PM
When "function pointer" meets "template"... I can't get rid of this compiling er cyu021 Linux - Software 3 12-17-2004 07:52 PM
function prototypes in template class' (c++) qwijibow Programming 4 12-13-2004 09:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration