Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我的课是抽象的?它';s的覆盖似乎有相同的签名?_C++_C++11 - Fatal编程技术网

C++ 为什么我的课是抽象的?它';s的覆盖似乎有相同的签名?

C++ 为什么我的课是抽象的?它';s的覆盖似乎有相同的签名?,c++,c++11,C++,C++11,我正在从事一个具有如下类继承方案的项目: Drive | v FileDrive | v StreamDrive | v BufferStreamDrive_base | v BufferStreamDrive virtual Drive::Type GetDriveType(void) const = 0; libtool: compile: x86_64-w64-mingw32.shared-g++ -DHAVE_CONF

我正在从事一个具有如下类继承方案的项目:

Drive
    |
    v
FileDrive
    |
    v
StreamDrive
    |
    v
BufferStreamDrive_base
    |
    v
BufferStreamDrive
virtual Drive::Type GetDriveType(void) const = 0;
libtool: compile:  x86_64-w64-mingw32.shared-g++ -DHAVE_CONFIG_H -I. -I../../include -I../../include -I./../../include -I./../../libraries/libmbc -I./../../libraries/libmbutil -I./../../libraries/libmbmath -I./../../libraries/libmbwrap -I./../../libraries/libann -I./../../mbdyn -I./../../mbdyn/base -I./../../mbdyn/struct -I./../../mbdyn/aero -I./../../mbdyn/elec -I./../../mbdyn/thermo -I./../../mbdyn/hydr -I./../../modules -I/opt/mxe/usr/x86_64-w64-mingw32.static/include/suitesparse -std=c++11 -D_USE_MATH_DEFINES -pthread -MT constltp_impl.lo -MD -MP -MF .deps/constltp_impl.Tpo -c constltp_impl.cc  -DDLL_EXPORT -DPIC -o .libs/constltp_impl.o
In file included from dataman.h:43:0,
                 from bufferstreamdrive.cc:36:
bufferstreamdrive.cc: In function 'Drive* ReadBufferStreamDrive(const DataManager*, MBDynParser&, unsigned int)':
bufferstreamdrive.cc:291:21: error: invalid new-expression of abstract class type 'BufferStreamDrive'
     InputEvery, pSDE));
                     ^
./../../libraries/libmbutil/mynewmem.h:658:14: note: in definition of macro 'SAFENEWWITHCONSTRUCTOR_'
  (pnt) = new constructor
              ^
bufferstreamdrive.cc:287:3: note: in expansion of macro 'SAFENEWWITHCONSTRUCTOR'
   SAFENEWWITHCONSTRUCTOR(pDr, BufferStreamDrive,
   ^
In file included from bufferstreamdrive.cc:39:0:
bufferstreamdrive.h:68:7: note:   because the following virtual functions are pure within 'BufferStreamDrive':
 class BufferStreamDrive : public BufferStreamDrive_base {
       ^
In file included from tpldrive.h:35:0,
                 from rbk.h:38,
                 from reffrm.h:44,
                 from mbpar.h:110,
                 from dataman.h:47,
                 from bufferstreamdrive.cc:36:
drive.h:117:22: note:   virtual Drive::Type Drive::GetDriveType() const
  virtual Drive::Type GetDriveType(void) const = 0;
                      ^
Drive
中,有一个声明如下的虚拟方法:

Drive
    |
    v
FileDrive
    |
    v
StreamDrive
    |
    v
BufferStreamDrive_base
    |
    v
BufferStreamDrive
virtual Drive::Type GetDriveType(void) const = 0;
libtool: compile:  x86_64-w64-mingw32.shared-g++ -DHAVE_CONFIG_H -I. -I../../include -I../../include -I./../../include -I./../../libraries/libmbc -I./../../libraries/libmbutil -I./../../libraries/libmbmath -I./../../libraries/libmbwrap -I./../../libraries/libann -I./../../mbdyn -I./../../mbdyn/base -I./../../mbdyn/struct -I./../../mbdyn/aero -I./../../mbdyn/elec -I./../../mbdyn/thermo -I./../../mbdyn/hydr -I./../../modules -I/opt/mxe/usr/x86_64-w64-mingw32.static/include/suitesparse -std=c++11 -D_USE_MATH_DEFINES -pthread -MT constltp_impl.lo -MD -MP -MF .deps/constltp_impl.Tpo -c constltp_impl.cc  -DDLL_EXPORT -DPIC -o .libs/constltp_impl.o
In file included from dataman.h:43:0,
                 from bufferstreamdrive.cc:36:
bufferstreamdrive.cc: In function 'Drive* ReadBufferStreamDrive(const DataManager*, MBDynParser&, unsigned int)':
bufferstreamdrive.cc:291:21: error: invalid new-expression of abstract class type 'BufferStreamDrive'
     InputEvery, pSDE));
                     ^
./../../libraries/libmbutil/mynewmem.h:658:14: note: in definition of macro 'SAFENEWWITHCONSTRUCTOR_'
  (pnt) = new constructor
              ^
bufferstreamdrive.cc:287:3: note: in expansion of macro 'SAFENEWWITHCONSTRUCTOR'
   SAFENEWWITHCONSTRUCTOR(pDr, BufferStreamDrive,
   ^
In file included from bufferstreamdrive.cc:39:0:
bufferstreamdrive.h:68:7: note:   because the following virtual functions are pure within 'BufferStreamDrive':
 class BufferStreamDrive : public BufferStreamDrive_base {
       ^
In file included from tpldrive.h:35:0,
                 from rbk.h:38,
                 from reffrm.h:44,
                 from mbpar.h:110,
                 from dataman.h:47,
                 from bufferstreamdrive.cc:36:
drive.h:117:22: note:   virtual Drive::Type Drive::GetDriveType() const
  virtual Drive::Type GetDriveType(void) const = 0;
                      ^
然后在
FileDrive
中,它被以下内容覆盖:

virtual Drive::Type GetDriveType(void) const;
通过以下实施:

Drive::Type
FileDrive::GetDriveType(void) const
{
    return Drive::FILEDRIVE;
}
但是,当我编译代码时,会出现如下错误:

Drive
    |
    v
FileDrive
    |
    v
StreamDrive
    |
    v
BufferStreamDrive_base
    |
    v
BufferStreamDrive
virtual Drive::Type GetDriveType(void) const = 0;
libtool: compile:  x86_64-w64-mingw32.shared-g++ -DHAVE_CONFIG_H -I. -I../../include -I../../include -I./../../include -I./../../libraries/libmbc -I./../../libraries/libmbutil -I./../../libraries/libmbmath -I./../../libraries/libmbwrap -I./../../libraries/libann -I./../../mbdyn -I./../../mbdyn/base -I./../../mbdyn/struct -I./../../mbdyn/aero -I./../../mbdyn/elec -I./../../mbdyn/thermo -I./../../mbdyn/hydr -I./../../modules -I/opt/mxe/usr/x86_64-w64-mingw32.static/include/suitesparse -std=c++11 -D_USE_MATH_DEFINES -pthread -MT constltp_impl.lo -MD -MP -MF .deps/constltp_impl.Tpo -c constltp_impl.cc  -DDLL_EXPORT -DPIC -o .libs/constltp_impl.o
In file included from dataman.h:43:0,
                 from bufferstreamdrive.cc:36:
bufferstreamdrive.cc: In function 'Drive* ReadBufferStreamDrive(const DataManager*, MBDynParser&, unsigned int)':
bufferstreamdrive.cc:291:21: error: invalid new-expression of abstract class type 'BufferStreamDrive'
     InputEvery, pSDE));
                     ^
./../../libraries/libmbutil/mynewmem.h:658:14: note: in definition of macro 'SAFENEWWITHCONSTRUCTOR_'
  (pnt) = new constructor
              ^
bufferstreamdrive.cc:287:3: note: in expansion of macro 'SAFENEWWITHCONSTRUCTOR'
   SAFENEWWITHCONSTRUCTOR(pDr, BufferStreamDrive,
   ^
In file included from bufferstreamdrive.cc:39:0:
bufferstreamdrive.h:68:7: note:   because the following virtual functions are pure within 'BufferStreamDrive':
 class BufferStreamDrive : public BufferStreamDrive_base {
       ^
In file included from tpldrive.h:35:0,
                 from rbk.h:38,
                 from reffrm.h:44,
                 from mbpar.h:110,
                 from dataman.h:47,
                 from bufferstreamdrive.cc:36:
drive.h:117:22: note:   virtual Drive::Type Drive::GetDriveType() const
  virtual Drive::Type GetDriveType(void) const = 0;
                      ^
这里有什么问题?我看不见

编辑

我将override关键字添加到
FileDrive
类方法中,如下所示:

virtual Drive::Type GetDriveType(void) const override;
这将导致以下错误,确认它不会覆盖任何内容。我觉得奇怪的是,这个错误指的是
GetDriveTypeA

libtool: compile:  x86_64-w64-mingw32.shared-g++ -DHAVE_CONFIG_H -I. -I../../include -I../../include -I./../../include -I./../../libraries/libmbc -I./../../libraries/libmbutil -I./../../libraries/libmbmath -I./../../libraries/libmbwrap -I./../../libraries/libann -I./../../mbdyn -I./../../mbdyn/base -I./../../mbdyn/struct -I./../../mbdyn/aero -I./../../mbdyn/elec -I./../../mbdyn/thermo -I./../../mbdyn/hydr -I./../../modules -I/opt/mxe/usr/x86_64-w64-mingw32.static/include/suitesparse -std=c++11 -D_USE_MATH_DEFINES -pthread -MT bicg.lo -MD -MP -MF .deps/bicg.Tpo -c bicg.cc  -DDLL_EXPORT -DPIC -o .libs/bicg.o
In file included from /opt/mxe/usr/x86_64-w64-mingw32.shared/include/winsock2.h:10:0,
                 from usesock.h:41,
                 from dataman.h:75,
                 from solver.h:59,
                 from bicg.cc:46:
filedrv.h:60:22: error: 'virtual Drive::Type FileDrive::GetDriveTypeA() const' marked 'override', but does not override
  virtual Drive::Type GetDriveType(void) const override;
                  ^

我正在从Linux为windows交叉编译这段代码(我以前为本机Linux干净地编译了这段代码,但没有
-std=c++11
,所以我认为错误可能与此有关)。然而,现在我在谷歌上搜索发现,有一个windows
GetDriveType
函数的别名是
GetDriveTypeA
。这可能是微软进入我的代码的某种宏疯狂吗?

有一个c++11功能,名为
override
。将其添加到应该重写基类函数的函数声明末尾。如果没有,编译器将指出错误。如果没有,除了猜测之外,很难做任何事情。如果你想
覆盖
a
virtual
函数,请使用。这将使诊断问题变得更容易。我想说,绝对是宏观疯狂。我相信有两个函数声明
GetDriveType
GetDriveTypeA
,并且只定义了其中一个。通常
A
版本使用ASCII字符串,而另一个版本使用wchar字符串。
Drive::type
Drive::FILEDRIVE
的类型定义是什么?它们是字符串吗?啊,Windows宏。大家最喜欢的C++问题。