目前,我试图让下面的代码进行编译:外部类内部类 - 实例化内部类作为外部类的成员
terminallog.hh
#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;
};
terminallog.cc
// stripped code
Terminallog::Terminallog() {
Warn this->warn();
}
Terminallog::Warn::Warn() {
this->lineended = true;
}
//stripped code
那么,正如你可能猜到alredy,它的失败;-)。我的编译器说:
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)’
这让我没有选择权。我显然做错了,但我不知道如何解决这个问题。我会很感激任何提示。
在此先感谢
ftiaronsem
阅读您的错误信息 - 你不发布正确的代码 - 你有一个'警告warn'成员变量和一个'警告无效(的std :: string)'成员函数,将其重命名 – Erik 2011-03-27 17:19:17
之一@埃里克。 Uups,完全正确,并且非常令人印象深刻;-)。这个班里有更多的代码,我剥夺了。非常感谢您指出这一点。 – ftiaronsem 2011-03-27 17:26:04