
Untitled
By: a guest on
Jun 25th, 2012 | syntax:
None | size: 1.11 KB | hits: 14 | expires: Never
Outer class containing inner class - instantiate the inner class as a member of the outer class
#ifndef TERMINALLOG_HH
#define TERMINALLOG_HH
#include <string>
#include <sstream>
#include <iostream>
class Terminallog {
public:
Terminallog();
virtual ~Terminallog();
class Warn {
public:
Warn();
private:
bool lineended;
};
friend class Terminallog::Warn;
protected:
private:
Warn warn;
};
// stripped code
Terminallog::Terminallog() {
Warn this->warn();
}
Terminallog::Warn::Warn() {
this->lineended = true;
}
//stripped code
g++ src/terminallog.cc inc/terminallog.hh -o test -Wall -Werror
In file included from src/terminallog.cc:8:
src/../inc/terminallog.hh:56: error: declaration of ‘Terminallog::Warn Terminallog::warn’
src/../inc/terminallog.hh:24: error: conflicts with previous declaration ‘void Terminallog::warn(std::string)’
Terminallog::Terminallog() : warn()
{
// other constructor code
}
// note that `Warn::Warn()` is invoked implicitly on `wake`, so
TerminalLog::Terminallog() {}
// would be equivalent