简体   繁体   English

包含的功能隐藏了重载的虚拟功能

[英]Included function hides overloaded virtual functions

I am developing a system using OpenCV. 我正在使用OpenCV开发系统。 This system has a class with a virtual function which has the same name (train) as a virtual function used by OpenCV. 该系统具有带有虚拟功能的类,该类具有与OpenCV使用的虚拟功能相同的名称(序列)。 When I compile, I get the following warning: 编译时,出现以下警告:

/opt/local/include/opencv2/ml/ml.hpp:957:18: warning: 'CvForestTree::train' hides overloaded virtual functions [-Woverloaded-virtual] /opt/local/include/opencv2/ml/ml.hpp:957:18:警告:“ CvForestTree :: train”隐藏了重载的虚拟函数[-Woverloaded-virtual]

Most questions related to hiding overloaded virtual functions deal with classes and derived classes, but in this case my (perhaps incorrect) assumption the problem is that a class OpenCV implements has a function with the same name. 与隐藏重载的虚拟函数有关的大多数问题都涉及类和派生类,但是在这种情况下,我(也许是错误的)假设问题是OpenCV实现的类具有同名函数。 Note that OpenCV headers must be included for my class definition of the function to work. 请注意,必须包含OpenCV标头才能使我的函数的类定义起作用。

Obviously, I'd prefer not to change the name of the function in the class I made and I suspect I am doing something stupid to get this problem. 显然,我宁愿不要在我创建的类中更改函数的名称,并且我怀疑自己在做一些愚蠢的事情来解决此问题。

EDIT: CvForestTree is OpenCV's class, not mine. 编辑:CvForestTree是OpenCV的类,而不是我的。 I'm not sure the exact area of line of code that causes the problem because the warning occurs for any file that includes OpenCV headers. 我不确定导致问题的代码行的确切区域,因为包含OpenCV标头的任何文件都会发生警告。 Maybe that means it is an OpenCV bug. 也许这意味着它是一个OpenCV错误。

The problem isn't with your code but the code of OpenCV: the CvForestTree class derives from CvTree and both classes have [virtual] train() member functions. 问题不在于您的代码,而是OpenCV的代码: CvForestTree类派生自CvTree并且两个类均具有[virtual] train()成员函数。 Since the CvForestTree doesn't override all three overloads (I don't know if it overrides any but there are two train() overloads in CvForestTree and three in CvTree ), at least one of the CvTree::train() functions is hidden. 由于CvForestTree不会覆盖所有三个重载(我不知道是否覆盖了所有重载, CvForestTree有两个train()重载,而CvForestTree三个CvTree ),因此至少隐藏了一个CvTree::train()函数。 。

The fix to the problem is to have a declaration like 解决该问题的方法是像这样声明

using CvTree::train;

in the definition of CvForestTree . CvForestTree的定义中。 Of course, this isn't your class. 当然,这不是您的课程。 That's one of the problems with warnings: The are often emitted for code you don't control. 这是警告的问题之一:经常为您无法控制的代码发出警告。

In fact you have to add this using CvDTree::train; 实际上,您必须使用CvDTree :: train添加它; in couple of places in ml.hpp: 在ml.hpp中的几个地方:

class CV_EXPORTS CvBoostTree: public CvDTree
{
public:
  using CvDTree::train;
    CvBoostTree();


class CV_EXPORTS CvForestTree: public CvDTree
{
public:
  using CvDTree::train;
    CvForestTree();

My solution was to add using CvDTree::train; 我的解决方案是using CvDTree::train; in two lines within include/opencv2/ml/ml.hpp . include/opencv2/ml/ml.hpp中的两行中。 1.Within CvForestTree class definition: 1.在CvForestTree类定义内:

class CV_EXPORTS CvForestTree: public CvDTree
{
using CvDTree::train;

2. Within CvBoostTree class definition: 2.在CvBoostTree类定义内:

class CV_EXPORTS CvBoostTree: public CvDTree
{
using CvDTree::train;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM