.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
Calling template member functions??
Old
  (#1)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Calling template member functions?? - 25-02-2004

I don't get it.....
Code:
template <class Dummy> class TTest
{
public:
	template <typename C> void CallFunc(C *s, bool(C::*pMemberFunc)(void))
	{
		s->*pMemberFunc();
	};
};

class CTest
{
public:
	void bleh(void)
	{
		printf("Bleh\n");
	};
};

int main()
{
	TTest<short> *pTest = new TTest<short>;
	CTest Test2;
	pTest->CallFunc<CTest>(pTest, CTest::bleh);

	return 0;
}
gives me the error
Quote:
error C2275: 'CTest' : illegal use of this type as an expression
E:\bot_tools\test_proggie\test3\test3\test3.cpp(44 2) : see declaration of 'CTest'
Acoording to my c++ book I should do this to call the function
Code:
pTest->template CallFunc<CTest>(pTest, CTest::bleh);
but then I get this error;
Quote:
error C2951: template declarations are only permitted at global or namespace scope
Can anyone help me
  
Reply With Quote
Re: Calling template member functions??
Old
  (#2)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Calling template member functions?? - 25-02-2004

i have no clue what templates do, to me the above code looks like bloatware?


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Calling template member functions??
Old
  (#3)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Calling template member functions?? - 25-02-2004

LOL @Stefan He's talking about the C++ templates, which are a pre-made set of types and tools that can supposedly be used out of the box in any C/C++ program. It features linked lists, binary trees, hashtables, etc.

@Rick: never used them. Dunno Perhaps you can get a hint on how to use passed pointers to reference functions by looking at the AStarSearch() function in Count Floyd's POD-bot source code. He passes functions addresses as parameters of this function. It sounds like a pointer indirection problem, anyhow.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Calling template member functions??
Old
  (#4)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Calling template member functions?? - 25-02-2004

ehh templates are normal c++ Stefan So is the rest except the line whith the error I guess.

http://www.cplusplus.com/doc/tutorial/tut5-1.html

meh to late

I did some searching the problem is that int his line;
pTest->CallFunc<CTest2>(pTest, CTest::bleh);

the compiler sees the '<' and the '>' as less-and greater then operators...
After I searched a bit in my book it sayed you have to use the template keyword like I did but it seems that msvc 6.0 this doesn't support

Last edited by Rick; 25-02-2004 at 18:53..
  
Reply With Quote
Re: Calling template member functions??
Old
  (#5)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Calling template member functions?? - 25-02-2004

yes i know C++ has templates, still sounds like bloatware. I have read enough theories about "you can use your classes in other programs" , and i only got that working ONCE in my entire life...


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Calling template member functions??
Old
  (#6)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Calling template member functions?? - 25-02-2004

heh problem solved....
http://forums.thewavelength.net/inde...=0&#entry83190
  
Reply With Quote
Re: Calling template member functions??
Old
  (#7)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Calling template member functions?? - 25-02-2004

@stefan : template are often a great feature, I use them in my AStar code as you might have seen. But don't try to use them when wanting them to access via dynamic linking from a .dll for example, that's scary and results in more work than using another possibility, I once tried that in a NN - simulator ...

and yes, rick, that <...> stuff is mostly only needed when instantiating data elements. your problem is of course a bit more complicated, a template function inside a template class ...

maybe you should try to compose classes using virtual base classes and multilayered template constructs .... I guess that'd be almost the summit of crazyness ... I'm using some virtual base class in my bot - in theory everything is fine, but some fuckin' compilers don't like each part of those, creating warnings etc.. you won't guess which one


  
Reply With Quote
Re: Calling template member functions??
Old
  (#8)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Calling template member functions?? - 25-02-2004

hmm virtual base classes is one of those subjects i haven't read much on yet
But its working now, as long the compiler can find the right types for the variabeles all works fine.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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 On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com