J
Jay
Hi,
I know the standard disallows the following for non-const X&
parameters, i,e,
void func(X&);
... func(X()); ...
However, I can see a reasonable use for this pattern in constructor
initialization lists, e.g.
class C {
public:
C(const char* fSpec): abc_(InFile(fSpec)) {}
private:
ABC abc_;
}
InFile has non-const methods to read data from a file. However,
because of the above language restriction, I have to either use
const_cast on InFile, or go through all sorts of convolusions, making
the code unnecessarily complicated. Would it be considered bad style
to use const_cast on InFile in the above case, or is there a better
workaround?
Thanks.
I know the standard disallows the following for non-const X&
parameters, i,e,
void func(X&);
... func(X()); ...
However, I can see a reasonable use for this pattern in constructor
initialization lists, e.g.
class C {
public:
C(const char* fSpec): abc_(InFile(fSpec)) {}
private:
ABC abc_;
}
InFile has non-const methods to read data from a file. However,
because of the above language restriction, I have to either use
const_cast on InFile, or go through all sorts of convolusions, making
the code unnecessarily complicated. Would it be considered bad style
to use const_cast on InFile in the above case, or is there a better
workaround?
Thanks.