继承和虚拟功能
Inheritance and virtual function
我有一个具有虚拟函数updateCustom()和另一个基本函数checkneighbours()的class tableau()。我还有另一个从Tableau,Jeutaquin衍生而来的,它覆盖了UpdateCustom()。在UpdateCustom内部,我想致电checkneighbours(),但我会有一个错误。
我的两个功能在我的班级tableau中:
template<class T>
void updateCustom(char input) //Virtual function in .h
{}
template<class T>
Case<T>* Tableau<T>::checkNeighbours(const Case<T> **&plateau, int i, int j)
{
//No need to see what is inside this function
Case<T> *neighbours;
neighbours = new Case<T>[4];
for(int n = 0; n<taille;n++)
neighbours[n] = nullptr;
if(i!=0)
neighbours[0] = plateau[i-1][j];
if(j!=taille)
neighbours[1] = plateau[i][j+1];
if(i!=taille)
neighbours[2] = plateau[i+1][j];
if(j!=0)
neighbours[3] = plateau[i][j-1];
return neighbours;
}
然后在Jeutaquin内部(源自Tableau):
template<class T>
void JeuTaquin<T>::updateCustom(char input)
{
//Here is my function checkNeighbours that I want to call
Case<T> *neighbours = Tableau<T>::checkNeighbours(Tableau<T>::plateau1, 2, 2);
}
当我尝试编译时,我会得到:
JeuTaquin.cpp:54:71: error: no matching function for call to ‘JeuTaquin<int>::checkNeighbours(Case<int>**&, int, int)’
neighbours = Tableau<T>::checkNeighbours(Tableau<T>::plateau1, 2, 2);
JeuTaquin.cpp:54:71: note: candidate is:
In file included from JeuTaquin.h:5:0,
from JeuTaquin.cpp:1:
Tableau.h:78:11: note: Case<T>* Tableau<T>::checkNeighbours(const Case<T>**&, int, int) [with T = int]
Case<T>* checkNeighbours(const Case<T> **&plateau, int i, int j);
Tableau.h:78:11: note: no known conversion for argument 1 from ‘Case<int>**’ to ‘const Case<int>**&’
我不知道为什么我无法识别我的updatecustom()内的checkneighbours。我的包含还可以,我什至在Jeutaquin的构造函数中拨打了Tableau的功能,而且效果很好!谢谢您的帮助
编辑:我在Tableau.h中声明我的UpdateCustom函数:
virtual void updateCustom(char input);
将 Type**
施加到 const Type**
。
请参阅http://c-faq.com/ansi/constmismatch.html有关原因的解释。
相关文章:
- 如何在C++中获得"静态纯虚拟"功能?
- std::is_trivially_copyable_v 关于虚拟功能
- 类似虚拟的朋友功能?
- 是否有任何模式等效于虚拟模板功能?
- 隐藏重载虚拟功能的模板化访客:SFINAE 在使用?
- 为什么我无法覆盖虚拟功能?
- 二叉搜索树 - 使用 Linux 在虚拟机中制作删除功能
- 虚拟功能不起作用
- 如果在创建对象时创建了 VPTR,那么为什么具有虚拟功能的类的大小在 32 位系统上为 4,在 64 位机器上为 8
- 虚拟功能如何影响static_cast?
- __declspec(属性)和虚拟功能
- 实现来自第三方类的虚拟功能
- 消除未使用的虚拟功能
- 为什么虚拟继承即使不涉及虚拟功能也需要 vtable?
- C 虚拟功能的输出
- 抽象类 A 由类 C 继承"through"类 B "intermediary"。如何声明虚拟功能?
- 虚拟功能是否不太可能导致堆栈溢出
- 使用继承和虚拟功能应用五个规则
- 父会员功能中虚拟函数的C 行为
- 在多态性中重新定义功能(虚拟),具有不同数量的参数