On Oct 12, 3:22 pm, Adam Nielsen <adam.niel...@remove.this.uq.edu.au>
wrote:
> I'm trying to work out how to construct a temporary object in a class'
> initialisation list and then call a function on it, in order to pass the
> result to a base class' constructor.
> struct PrintNumber: public PrintString
> {
> PrintNumber(int iNumber)
> : PrintString(
> // How should this be done?
> (std:
stringstream() << "The number is " << iNumber).str()
> )
> {
> }
> };
I would write:
struct PrintNumber: public PrintString
{
PrintNumber(int iNumber) : PrintString( convert_number(iNumber) ) {}
private:
std::string convert_number(int n)
{
std:

stringstream oss;
oss << "The number is " << n;
return oss.str();
}
};