复制构造函数:深度复制抽象类 [英] Copy constructor: deep copying an abstract class
本文介绍了复制构造函数:深度复制抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下情况(简化的情况):
Suppose I have the following (simplified case):
class Color;
class IColor
{
public:
virtual Color getValue(const float u, const float v) const = 0;
};
class Color : public IColor
{
public:
float r,g,b;
Color(float ar, float ag, float ab) : r(ar), g(ag), b(ab) {}
Color getValue(const float u, const float v) const
{
return Color(r, g, b)
}
}
class Material
{
private:
IColor* _color;
public:
Material();
Material(const Material& m);
}
现在,有什么办法让我对摘要进行深层复制吗Material的副本构造函数中的IColor?也就是说,我希望复制任何m._color的值(颜色,纹理),而不仅是指向IColor的指针。
Now, is there any way for me to do a deep copy of the abstract IColor in the copy constructor of Material? That is, I want the values of whatever m._color might be (a Color, a Texture) to be copied, not just the pointer to the IColor.
推荐答案
这篇关于复制构造函数:深度复制抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文