Passing a reference to an internal class
From: Peter Gordon (petergo_at__deleteme_.netspace.net.au)
Date: 03/14/05
- Next message: Edd: "Re: Passing a reference to an internal class"
- Previous message: Anthony Borla: "Re: how to make object sortable for use in STL containers"
- Next in thread: Edd: "Re: Passing a reference to an internal class"
- Reply: Edd: "Re: Passing a reference to an internal class"
- Reply: Anthony Borla: "Re: Passing a reference to an internal class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Mar 2005 00:46:37 +0000 (UTC)
Is it possible to pass a reference defined in a class
to an internal class? In the code below, the constructor
for class B does not compile.
#include <fstream>
class A {
public:
A(std::ifstream& _afin) : afin(_afin) {}
std::ifstream& GetFileH() { return afin; }
class B {
B(std::ifstream& _bfin) :
bfin( _bfin = A::GetFileH(); ) {} // B constructor
private:
std::ifstream& bfin;
};
private:
std::ifstream& afin;
};
int main() {
std::ifstream fileH;
fileH.open("afile");
class A x(fileH);
return 0;
}
- Next message: Edd: "Re: Passing a reference to an internal class"
- Previous message: Anthony Borla: "Re: how to make object sortable for use in STL containers"
- Next in thread: Edd: "Re: Passing a reference to an internal class"
- Reply: Edd: "Re: Passing a reference to an internal class"
- Reply: Anthony Borla: "Re: Passing a reference to an internal class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|