P
Programmer
This may sound easy and it probably is, I just started learning C++.
I have a class that writes to a file and I would like to add a second
optional parameter that will be used to tell the class if a newline
character should be written so the next output will start on a new line.
My class looks like this:
class Debug {
public:
Debug();
void Open(string);
void Write(string,bool);
void Write(float,bool);
void Write(int,bool);
void Write(double,bool);
void Write(char,bool);
~Debug();
private:
ofstream outDebug;
};
And my definition of one of these looks like this:
void Debug::Write(string sDebug, bool bNewLine = true) {
if(bNewLine) {
outDebug << sDebug << endl;
} else {
outDebug << sDebug;
}
}
I want to set it up so that by default, it will write a new line, but it can
be overridden by sending a 'false' as the second parameter. However, I am
getting a "Write: no overloaded function takes 1 parameters" error when I
try to compile. The call looks like this:
DebugFile.Write("Debug File Opened");
I could write it like this, DebugFile.Write("Debug File Opened",true), but
since true is the default and the mode I will use 90% of the time, I was
hoping to be able to default to true so my calls will be shorter.
Any ideas?
Thanks in advance
John
I have a class that writes to a file and I would like to add a second
optional parameter that will be used to tell the class if a newline
character should be written so the next output will start on a new line.
My class looks like this:
class Debug {
public:
Debug();
void Open(string);
void Write(string,bool);
void Write(float,bool);
void Write(int,bool);
void Write(double,bool);
void Write(char,bool);
~Debug();
private:
ofstream outDebug;
};
And my definition of one of these looks like this:
void Debug::Write(string sDebug, bool bNewLine = true) {
if(bNewLine) {
outDebug << sDebug << endl;
} else {
outDebug << sDebug;
}
}
I want to set it up so that by default, it will write a new line, but it can
be overridden by sending a 'false' as the second parameter. However, I am
getting a "Write: no overloaded function takes 1 parameters" error when I
try to compile. The call looks like this:
DebugFile.Write("Debug File Opened");
I could write it like this, DebugFile.Write("Debug File Opened",true), but
since true is the default and the mode I will use 90% of the time, I was
hoping to be able to default to true so my calls will be shorter.
Any ideas?
Thanks in advance
John