passing a reference to xtor

From: JE (loomis53_at_cox.net)
Date: 09/30/04


Date: Thu, 30 Sep 2004 09:02:48 -0700

in the code below, I get the error:

In constructor `s::s(std::ifstream&)':
`good' undeclared (first use this function)

I have a feeling this is because I'm passing a reference to a
constructor, but don't understand why. Is it possible to this or
something similar to get the same effect (passing an opened file stream
to a class's constructor)?

#include <iostream>
#include <stdlib.h>

using namespace std;
class s {

public:
     s(ifstream& ifs);

};

s::s(ifstream& ifs) {
     ifs.good();
}



Relevant Pages

  • Re: Temporaries - when do they begin, when do they end?
    ... The constructor accepts references - i.e. addresses to the objects passed. ... The return type is not a reference, so you create a temporary inside the ... Both question address to different issues - the warning is because you're ... passing a reference to Expr- in the second version you're passing that ...
    (comp.lang.cpp)
  • Re: Passing arguements by reference
    ... you are already passing a reference to an A object in to the constructor for B. ... If you don't wish to share the object, then you need to clone it and save the reference to the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Compiler error or? Microsoft VC++ v6.0
    ... > Because your passing an unsigned long the compiler can only assume ... > passing a reference so it uses the constructor that uses a reference. ...
    (microsoft.public.vc.language)
  • Passing a constructor ?
    ... I would like to write a function which can create an object by passing ... the object type and object constructor. ... The problem is with the last part: "passing the constructor to the ... function ReturnObject(const ParaClassType: Tclass): Tobject; ...
    (alt.comp.lang.borland-delphi)
  • Re: passing a reference to xtor
    ... > I have a feeling this is because I'm passing a reference to a ... > constructor, but don't understand why. ... > something similar to get the same effect (passing an opened file stream ... Sumit Rajan <sumit DOT rajan AT gmail DOT com> ...
    (alt.comp.lang.learn.c-cpp)