Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-25-2004, 08:53 PM   #1
LQ Newbie
Registered: Nov 2004
Posts: 1

Rep: Reputation: 0
Unhappy template class

Dear All,

I have problem on programming in template class.
#include <stdio.h>
template <class ArgType>
class ClassA
	template <class ClsType>
		void Func( ClsType* pObj, void (ClsType::*pClsFunc)(ArgType), ArgType arg )
		(pObj->*pClsFunc)( arg );

class ClassB
	void Func( int a )
		printf( "a=%d\n", a );

int main( int argc, char* argv[] )
	ClassA<int> a;
	ClassB b;

	a.Func( &b, ClassB::Func, 1 );

	return 0;
while i use g++ to compile the program, i got the following message

test.cpp: In function `int main(int, char**)':
test.cpp:28: no matching function for call to `ClassA<int>::Func(ClassB*,
<unknown type>, int)'
test.cpp:9: candidates are: void ClassA<ArgType>::Func(ClsType*, void
(ClsType::*)(ArgType), ArgType) [with ClsType = ClassB, ArgType = int]

But this program can be successfully compiled in VC++.

Please Help.

Reply me please

Last edited by ckcheung0927; 11-25-2004 at 09:01 PM.
Old 11-26-2004, 02:03 PM   #2
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
You need to send a function pointer as argument in main. It should look like this:
int main( int argc, char* argv[] )
	ClassA<int> a;
	ClassB b;

	a.Func( &b, &ClassB::Func, 1 );
	// Note the '&' before ClassB::Func

	return 0;
Old 11-26-2004, 02:51 PM   #3
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
Old 11-28-2004, 04:59 PM   #4
Registered: Jul 2004
Posts: 60

Rep: Reputation: 15
looks like you're kinda new to templates. I use this tutorial which helped me.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

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++ class template doesn't work!! tagigogo Programming 2 11-02-2005 05:45 PM
Template class with a template member... Nicholas Bishop Programming 3 02-21-2005 09:27 PM
function prototypes in template class' (c++) qwijibow Programming 4 12-13-2004 10:34 AM
C++ - class template - linker errors? Wynd Programming 2 10-19-2004 04:54 PM
C++ template class syntax rong Programming 12 08-13-2003 01:26 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 PM.

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