file handling question


Hi I'm new to c++. I'm working on a code which got a code line following:

code :
class TextUpwardProtocol: public UpwardProtocol {
private:
FILE* stream;
Public: TextUpwardProtocol(FILE* _stream): stream(_stream) {}

i Didn't understand the line "TextUpwardProtocol(FILE* _stream): stream(_stream)"
{}
I know this is the constructor of class but the part confusing me is _stream and : stream(-stream) look like an inheritance. I check the base class too but there is no such member like _string . I really don't know what is the meaning of this line

So my question are following :

1:what is the meaning of this code line ?
2: is it a constructor call or something else please explain;
3:what the meaning of" : stream(-stream)" or "("File * _stream)" ?
4 what is that underscore sign "_" doing ?

2nd I got another code line which is following:

code:
class BinaryProtocol: public Protocol {
private:
DownwardProtocol* handler;
BinaryProtocol(FILE* down, DownwardProtocol* _handler, FILE* up) {
handler = _handler;
}


Now my question are following :
1: meaning of line "handler = _handler;" ?
2: Is there a class handler in system or c++ ;
3:what kind of data is _handeler ?
4: while handler is a pointer type it should have address of its class or its base class or drive class but i checked all of that but there is no such thing like _handler, so what is _handler is doing here ?
5: Is there is a concept behind using underscore "_" mark in c++ ? as far as i know we can use underscore in variables name .


Please help me with these issue.





1
2
3
4
5
6
class TextUpwardProtocol: public UpwardProtocol {
private:
FILE* stream;
Public:
TextUpwardProtocol(FILE* _stream): stream(_stream) {}
};


Constructor can be written also like following.
1
2
3
4
TextUpwardProtocol(FILE* _stream)
{
stream = _stream;
}


First style is sometimes cleaner to read.
Last edited on
For FILE* _stream or other pointer variables, it is always wise to check it is valid before using it.
Topic archived. No new replies allowed.