Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* DEC C++ template problem
@ 1994-05-16 19:06 Andrew Staniszewski
  1994-05-26 12:34 ` Etienne Frejaville
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Staniszewski @ 1994-05-16 19:06 UTC (permalink / raw)




I need to write some code taking advantage of the flexability of templates. 
But the DEC C++ compiler is being rather noisome. My specific problem 
lies in passing a member function from a paramatized type, specificly

-----------------------------------------------------------------------------
include <iostream.h>
class foo
{
public:
  int barr() { return 0;}
};

template <class type> int func(type data,int (type::*memberFunc)())
{
  return data.memberFunc();
}


void main()
{
  foo data;

  cout << func(data,&foo::barr) << endl;
}
--------------------------------------------------------------------------------


generates the message from the compiler

chirpa> cxx -c test.cxx
	test.cxx:8: error: In the declaration of "memberFunc", type is not a class, 
	struct, or union type.
	Compilation terminated with errors.
The only way I can get this to compile is to declare memberFunc to belong 
explicily to foo. I THINK this is a compiler bug, but can anyone tell me for sure?

-- 
------------------------------------------------------------------------------
Andrew Staniszewski
staniszewski@mayo.edu
------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: DEC C++ template problem
  1994-05-16 19:06 DEC C++ template problem Andrew Staniszewski
@ 1994-05-26 12:34 ` Etienne Frejaville
  0 siblings, 0 replies; 2+ messages in thread
From: Etienne Frejaville @ 1994-05-26 12:34 UTC (permalink / raw)


In article <2r8g7q$gsq@fermat.mayo.edu>, stan@chirpa.mayo.edu (Andrew Staniszewski) writes:
|> 
|> 
|> I need to write some code taking advantage of the flexability of templates. 
|> But the DEC C++ compiler is being rather noisome. My specific problem 
|> lies in passing a member function from a paramatized type, specificly
|> 
|> -----------------------------------------------------------------------------
|> include <iostream.h>
|> class foo
|> {
|> public:
|>   int barr() { return 0;}
|> };
|> 
|> template <class type> int func(type data,int (type::*memberFunc)())
|> {
|>   return data.memberFunc();
|> }
|> 
|> 
|> void main()
|> {
|>   foo data;
|> 
|>   cout << func(data,&foo::barr) << endl;
|> }
|> --------------------------------------------------------------------------------
|> 
|> 
|> generates the message from the compiler
|> 
|> chirpa> cxx -c test.cxx
|> 	test.cxx:8: error: In the declaration of "memberFunc", type is not a class, 
|> 	struct, or union type.
|> 	Compilation terminated with errors.
|> The only way I can get this to compile is to declare memberFunc to belong 
|> explicily to foo. I THINK this is a compiler bug, but can anyone tell me for sure?

Your problem is that you try to invoke memberFunc as if it was a member function.
But you have declared it as a pointer to member function.
Use the right operator : the pointer to member operator '.*'.

replace :

 return data.memberFunc();

by :

 return (data.*memberFunc)();

and it will work fine.

I don't have interests in the products of DEC, but read CAREFULLY the ARM or
any recent ANSI C++ draft before thinking of a compiler bug.

--------Etienne FREJAVILLE---Bull S.A   ---------------------------------
 OSS/HEU/ACS/LPS/TOPAS                  e-mail: E.Frejaville@frcl.bull.fr
 Rue Jean-Jaures, F6/1D/17, BP 53       tel: (33-1) 30806548
 78340 Les Clayes-sous-Bois, France     Fax: (33-1) 30807950



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1994-05-26 12:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-05-16 19:06 DEC C++ template problem Andrew Staniszewski
1994-05-26 12:34 ` Etienne Frejaville

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox