N
neel
Hi,
I was wondering if there is any recommendation/guideline about similar
situation depicted in example given below:
class File {
bool CreateFile(const std::string & filename) {
CreateSpaceInFileSystemIfRequired();
// create file here..
}
bool CreateSpaceInFileSystemIfRequired() const {
SomeGlobalOrAnotherClassFunctionThatCreatesSpace();
}
};
C++ semantics dictate that as long as
"CreateSpaceInFileSystemIfRequired" does not change member of *File*
class, it should be okay to declare it as const. But, from point of
view of class functionality itself,
"CreateSpaceInFileSystemIfRequired" in a way cheats - without creating
space, it may not be possible to create file and although it's not
changing the file, from point of view of operation, it still is
affecting outcome of operation.
So in conjugation with operation or class functionality, I am of the
opinion that "CreateSpaceInFileSystemIfRequired" should be either non-
const or static member function. Is there any recommendation/
documentation regarding this scenario?
Thank in advance,
-Neel.
I was wondering if there is any recommendation/guideline about similar
situation depicted in example given below:
class File {
bool CreateFile(const std::string & filename) {
CreateSpaceInFileSystemIfRequired();
// create file here..
}
bool CreateSpaceInFileSystemIfRequired() const {
SomeGlobalOrAnotherClassFunctionThatCreatesSpace();
}
};
C++ semantics dictate that as long as
"CreateSpaceInFileSystemIfRequired" does not change member of *File*
class, it should be okay to declare it as const. But, from point of
view of class functionality itself,
"CreateSpaceInFileSystemIfRequired" in a way cheats - without creating
space, it may not be possible to create file and although it's not
changing the file, from point of view of operation, it still is
affecting outcome of operation.
So in conjugation with operation or class functionality, I am of the
opinion that "CreateSpaceInFileSystemIfRequired" should be either non-
const or static member function. Is there any recommendation/
documentation regarding this scenario?
Thank in advance,
-Neel.