作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里遇到了一个奇怪的场景......我有一个对模板化基类进行多重继承的类,我想在我的最终派生类中用一个模板化实现来实现
模板化基础:
//simple class with a pure virtual function DoFoo()
template <typename T>
struct foo
{
virtual T DoFoo() = 0;
};
//a simple class that inherits from foo, but does not implemented DoFoo()
struct bar {};
struct base2 : public foo<bar>
{
};
//a class that inherits from base2, and foo<bar2>,
//that needs an implementation of DoFoo for both bar and bar2 types.
struct bar2{};
struct final : public base2, public foo<bar2>
{
template <T>
T DoFoo(){ return T();}
};
最佳答案
However, it appears as though the compiler believes that the DoFoo() functions, for bar and bar2 are missing
foo::DoFoo
命名为
foo
成员函数。
final::DoFoo
命名成员模板,而不是成员函数。
final::DoFoo<int>
确实命名了一个成员函数,其定义是通过实例化该模板生成的,但成员函数的名称是
final::DoFoo<int>
-- 那个时候的尖括号只是它的拼写方式的一部分。
关于c++ - 模板化的成员函数可以实现两个基类的虚函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22340508/
我有一个特别的问题想要解决,我不确定是否可行,因为我找不到任何信息或正在完成的示例。基本上,我有: class ParentObject {}; class DerivedObject : publi
在我们的项目中,我们配置了虚 URL,以便用户可以在地址栏中输入虚 URL,这会将他们重定向到原始 URL。 例如: 如果用户输入'http://www.abc.com/partner ',它会将它们
我是一名优秀的程序员,十分优秀!