T
toton
Hi,
I have a parser interface , which is
class IParser{
public:
void readHeader(Document& doc)= 0;
void readCC(CC& cc) = 0;
};
Now, there are 3 kinds of parser which extends (implements) IParser,
one for XML, ne for Config, & one for binary.
They need to get the Document & CC class and fill the data, in the
document and CC.
Now document data's (like name, version) are private, and have a get
method. Once the document is set by the IParser implementation, it
should not be changed.
document class is like
class Document{
private:
std::string _name;
std::string _version;
public:
std::string getName() const{
return _name;
}
std::string getVersion() const{
return _version;
}
};
Now, declaring IParser as friend in document class is not helping, as
the actual implementation like class XMLParser, class ConfigParser are
not friend of Document, thus cant access Document private variables.
The classes are decalred like,
class XMLParser ublic IParser{
public:
void readHeader(Document& doc){
...
}
void readCC(CC& cc){
...
}
};
How to do this with or without friend? i.e. any class derived from
IParser can access the private variables of document?
any other better way this can be implemented? I had thought to create
the Document class inside readHeader, and initialize parameters
throught ctor, but Document class has a large number of such member
variables, and difficult to initialize all of them through ctor.
thanks in advance for advice ...
abir
I have a parser interface , which is
class IParser{
public:
void readHeader(Document& doc)= 0;
void readCC(CC& cc) = 0;
};
Now, there are 3 kinds of parser which extends (implements) IParser,
one for XML, ne for Config, & one for binary.
They need to get the Document & CC class and fill the data, in the
document and CC.
Now document data's (like name, version) are private, and have a get
method. Once the document is set by the IParser implementation, it
should not be changed.
document class is like
class Document{
private:
std::string _name;
std::string _version;
public:
std::string getName() const{
return _name;
}
std::string getVersion() const{
return _version;
}
};
Now, declaring IParser as friend in document class is not helping, as
the actual implementation like class XMLParser, class ConfigParser are
not friend of Document, thus cant access Document private variables.
The classes are decalred like,
class XMLParser ublic IParser{
public:
void readHeader(Document& doc){
...
}
void readCC(CC& cc){
...
}
};
How to do this with or without friend? i.e. any class derived from
IParser can access the private variables of document?
any other better way this can be implemented? I had thought to create
the Document class inside readHeader, and initialize parameters
throught ctor, but Document class has a large number of such member
variables, and difficult to initialize all of them through ctor.
thanks in advance for advice ...
abir