Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: E.Frejaville@frcl.bull.fr (Etienne Frejaville)
Subject: Re: DEC C++ template problem
Date: 26 May 94 12:34:16 GMT	[thread overview]
Message-ID: <1431@clbull.frcl.bull.fr> (raw)
In-Reply-To: 2r8g7q$gsq@fermat.mayo.edu

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



      reply	other threads:[~1994-05-26 12:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-05-16 19:06 DEC C++ template problem Andrew Staniszewski
1994-05-26 12:34 ` Etienne Frejaville [this message]
read-only archive

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