Re: void function returning value?

From: tom_usenet (tom_usenet_at_hotmail.com)
Date: 02/25/04


Date: Wed, 25 Feb 2004 14:32:05 +0000

On Wed, 25 Feb 2004 12:11:17 +0100, "Jochen Zeischka"
<jochen.zeischka@rug.ac.be> wrote:

>I'm puzzled. When compiling this:
>
>template<class ValRes, class Val1, class Val2>
>Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const
>Veld<Val2>& v2) {
> // something
> return res;
>}
>
>the compiler says:
>
>error C2562: 'mult' : 'void' function returning a value
>c:\fe dev\lin lag 9\veld.h(64) : see declaration of 'mult'
>
>which is the following line within the 'Veld' class:
>
> template<class ValRes, class Val1, class Val2>
> friend Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const
>Veld<Val2>& v2);
>
>forward declaration of the friend function was done as follows:
>
>template<class Val> class Veld;
>
>template<class ValRes, class Val1, class Val2>
>Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const
>Veld<Val2>& v2);
>
>Why is the compiler talking about a 'void' function? To me it seems that a
>'Veld<ValRes>&' is returned...

To me too. This compiled fine for me on 3 compilers:

template<class Val>
class Veld;

template<class ValRes, class Val1, class Val2>
Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const
Veld<Val2>& v2);

template<class Val>
class Veld
{
 template<class ValRes, class Val1, class Val2>
 friend Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1,
const Veld<Val2>& v2);
 //private var to test friendship
 Val v;
};

template<class ValRes, class Val1, class Val2>
Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const
Veld<Val2>& v2)
{
  res.v = v1.v + v2.v;
  return res;
}

int main()
{
  Veld<double> v1;
  Veld<int> v2;
  Veld<short> v3;
  Veld<double> v = mult(v1, v2, v3);
}

What compiler are you using? Can you post a complete program
exhibiting the error?

Tom

-- 
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html


Relevant Pages

  • Re: C03 abend when omitting CEE.SCEERUN from JCL
    ... The AMODE, RMODE, RENT, and RES information are link-edit information, not ... "compiler option" information. ... VS Cobol Program is actually OS/VS Cobol (amblist shows 5740CB103 as ... Do you mean VS COBOL II or OS/VS COBOL? ...
    (bit.listserv.ibm-main)
  • Re: Where are the Opteron F vs. Woodcrest reviews?
    ... (same typedef assumed) ... return res; ... sll %o1,7,%o5 ... Note that I'm not claiming that Sun's compiler is ...
    (comp.arch)
  • Re: tail call optimization
    ... (labels ((next (n l res) ... Namely, you are only thinking at the optimization quality of a compiler, not at the debuggability of the resulting code. ... developer, when looking at the stack trace, doesn't have the complete ... through the code (I'm not familiar with Lisp debugging yet, ...
    (comp.lang.lisp)
  • Re: passing a struct with an array by reference
    ... As res is of type MatlabWrap.micDataReturn which is decalred as struct, it means that res is ValueType. ... Value types gets allocated on stack, and because of that they have to be initialized befor they are first used, because the compiler doesn't make any assumptions about the res initial value. ... Because your method takes a ref parameter, then the compiler expects that this value is already initialized by you, and because it isn't, then it generate that error message. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is there a work-around
    ... >I'm trying to make a friend function out of a template parameter. ... it also fails with the Whidbey compiler I'll try to pass it on to MS. ... MVP VC++ FAQ: http://www.mvps.org/vcfaq ...
    (microsoft.public.vc.language)