我在说的是This。现在,我的问题是我有一个接口头文件,我真的不喜欢做任何实现。可以从该头中声明的基类派生的类采用这种习惯用法吗?因为据我所知,我必须为基类定义(受保护的)复制构造函数,这意味着我必须执行字符串(char *)副本。而且我不想将任何标头包含在我的接口标头文件中,因为this。有任何想法吗?虚拟构造函数问题
编辑:
class PluginFunction
{
public:
explicit PluginFunction(){}
virtual ~PluginFunction(){}
virtual int GetFunctionID() const = 0;
virtual const char* GetFunctionName() const = 0;
virtual bool EvalFunction(int&, RNode*, int){return true;}
virtual bool EvalFunction(double&, RNode*, int){return true;}
virtual bool EvalFunction(char*&, RNode*, int){return true;}
virtual PluginFunction* Clone();
protected:
explicit PluginFunction(const PluginFunction&)
{
//I dont want to strcpy :(which will have to include some header.
//Or I'll just iterate the buffer myself :).
}
private:
PluginFunction& operator=(const PluginFunction&);
int i_ID;
char* z_Name;
};
请张贴一些示例代码,但不清楚你的问题是什么。 – 2010-10-15 12:22:24
您的第一个问题请参阅工厂方法http://sourcemaking.com/design_patterns/factory_method。对于你的第二个问题,可以试用PIMPL的习惯用法。 http://www.gotw.ca/gotw/024.htm – DumbCoder 2010-10-15 12:53:24