使用clone()函数 [英] using clone() function
问题描述
你好专家!
我想创建一个虚拟克隆但是我不确定这是否是正确的方式。
有人能说出来吗我在代码中出错了。
我在这段代码中也遇到了一些编译错误。
哪些函数是正确的或哪些必须修改
班级基础
{
公开:
虚拟基础*克隆()= 0;
};
class Sub:public Base
{
public:
虚拟基础*克隆()= 0;
};
基础*子::克隆()
{return new Sub(* this); } $ / $
Base * copyObject(Base& baseObject)
{return baseObject.clone(); }
// Tony
非常感谢!
< blockquote> Tony Johansson sade:
Hello Experts!
我想创建一个虚拟克隆,但我不确定这是否是正确的方式。
有人可以告诉我在代码中出错的地方。
我在这段代码中也遇到了一些编译错误。
这些错误是什么?
哪些功能正确或哪些必须修改
类基地
公共:
虚拟基地*克隆()= 0;
类Sub:public Base
{
public:
virtual Base * clone()= 0;
虚拟基础*克隆();
或
基础*克隆();
};
Base * Sub :: clone()
{return new Sub(* this);基本* copyObject(Base& baseObject)
{return baseObject.clone(); //
非常感谢!
Tobias
-
重要提示:此电子邮件和附件的内容是保密的
,可能受法律保护和/或受版权保护。
禁止将其任何部分复制或传播给他人,并且可能是非法的。
Tobias Blomkvist < VO ** @ void.void> skrev i meddelandet
新闻:1124704386.64e6f0b347ca9e0f5008c632246aed1d@t eranews ...Tony Johansson sade:Hello Expert!
有人可以告诉我在代码中出错的地方。
我得到了这段代码也有一些编译错误。
那些错误是什么?
哪些功能正确或哪些必须修改
>班级基地
{
公开:
虚拟基地*克隆()= 0;
};
类子:公共基地
{
公开:
虚拟基地*克隆()= 0;
虚拟基地*克隆();
或
Base * clone();
};
Base * Sub :: clone()
{return new Sub (*这个);基本* copyObject(Base& baseObject)
{return baseObject.clone(); //
非常感谢!
这些错误是什么?
这是我得到的编译错误。
c:\Documents and Settings \Tony\kau\cplusplus\test15\base.h(15):错误C2143:
语法错误:在''public'之前缺少'';''
如何使用此克隆功能?
// Tony
class Base
{
public:
虚拟基础* clone()= 0;
};
类Sub:public Base
{
public:
virtual Base * clone(); /// = 0;这不应该在这里
//因为这会使它成为一个抽象
//类,所以你将无法写出
//返回新的Sub(* this);
};
Base * Sub :: clone()
{return new Sub(* this); } $ / $
Base * copyObject(Base& baseObject)
{return baseObject.clone(); }
Hello Experts!
I want to create a virtual clone but I''m not sure if this is the wright way.
Can somebody tell me where I have made error in the code.
I get some compile error in this code also.
Which functions are correct or which have to be modified
class Base
{
public:
virtual Base* clone() = 0;
};
class Sub : public Base
{
public:
virtual Base* clone() = 0;
};
Base* Sub::clone()
{ return new Sub(*this); }
Base* copyObject(Base& baseObject)
{ return baseObject.clone(); }
//Tony
Many thanks!
Tony Johansson sade:Hello Experts!
I want to create a virtual clone but I''m not sure if this is the wright way.
Can somebody tell me where I have made error in the code.
I get some compile error in this code also.
And those errors are?
Which functions are correct or which have to be modified
class Base
{
public:
virtual Base* clone() = 0;
};
class Sub : public Base
{
public:
virtual Base* clone() = 0;
virtual Base * clone();
or
Base * clone();
};
Base* Sub::clone()
{ return new Sub(*this); }
Base* copyObject(Base& baseObject)
{ return baseObject.clone(); }
//Tony
Many thanks!
Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
"Tobias Blomkvist" <vo**@void.void> skrev i meddelandet
news:1124704386.64e6f0b347ca9e0f5008c632246aed1d@t eranews...Tony Johansson sade:Hello Experts!
I want to create a virtual clone but I''m not sure if this is the wright
way.
Can somebody tell me where I have made error in the code.
I get some compile error in this code also.
And those errors are?Which functions are correct or which have to be modified
class Base
{
public:
virtual Base* clone() = 0;
};
class Sub : public Base
{
public:
virtual Base* clone() = 0;
virtual Base * clone();
or
Base * clone();};
Base* Sub::clone()
{ return new Sub(*this); }
Base* copyObject(Base& baseObject)
{ return baseObject.clone(); }
//Tony
Many thanks!
And those errors are?
This is the compile error I get.
c:\Documents and Settings\Tony\kau\cplusplus\test15\base.h(15): error C2143:
syntax error : missing '';'' before ''public''
How can main be used with this clone function?
//Tony
class Base
{
public:
virtual Base* clone() = 0;
};
class Sub : public Base
{
public:
virtual Base* clone();/// = 0; this should not be here
//since this will make it a Abstract
//class and so u will not be able to write
// return new Sub(*this);
};
Base* Sub::clone()
{ return new Sub(*this); }
Base* copyObject(Base& baseObject)
{ return baseObject.clone(); }
这篇关于使用clone()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!