相关疑难解决方法(0)

什么是未定义的引用/未解析的外部符号错误,我该如何解决?

什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?

随意编辑/添加您自己的.

c++ c++-faq linker-errors unresolved-external undefined-reference

1418
推荐指数
32
解决办法
52万
查看次数

你如何在C++中声明一个接口?

如何设置代表接口的类?这只是一个抽象的基类吗?

c++ inheritance abstract-class interface pure-virtual

781
推荐指数
11
解决办法
46万
查看次数

什么是多态,它是什么,以及它是如何使用的?

我正在观看Google Tech Talks视频,他们经常提到多态性.

什么是多态,它是什么,以及它是如何使用的?

oop polymorphism computer-science

541
推荐指数
12
解决办法
48万
查看次数

C++中的多态性

据我所知:

C++提供了三种不同类型的多态性.

  • 虚拟功能
  • 函数名称重载
  • 运算符重载

除了上述三种类型的多态性外,还存在其他种类的多态性:

  • 运行
  • 编译时间
  • ad-hoc多态性
  • 参数多态性

我知道运行时多态性可以通过虚函数实现 ,静态多态可以通过模板函数实现

但对于另外两个

ad-hoc多态性:

如果可以使用的实际类型的范围是有限的,并且必须在使用之前单独指定组合,则这称为ad-hoc多态.

参数多态性:

如果所有代码都是在没有提及任何特定类型的情况下编写的,因此可以透明地使用任意数量的新类型,这称为参数多态.

我几乎无法理解他们:(

任何人都可以用一个例子解释他们两个吗?我希望这些问题的答案对他们大学的许多新的消息有所帮助.

c++ polymorphism c++-faq

124
推荐指数
2
解决办法
5万
查看次数

未明确引用'vtable for xxx'

takeaway.o: In function `takeaway':
project:145: undefined reference to `vtable for takeaway'
project:145: undefined reference to `vtable for takeaway'
takeaway.o: In function `~takeaway':
project:151: undefined reference to `vtable for takeaway'
project:151: undefined reference to `vtable for takeaway'
takeaway.o: In function `gameCore':
project.h:109: undefined reference to `gameCore<int>::initialData(int)'
collect2: ld returned 1 exit status
make: *** [takeaway] Error 1
Run Code Online (Sandbox Code Playgroud)

我一直从链接器中获取此错误,我知道它与内联函数有关,可以暂时存储vtable.但是这需要我不太确定.我认为这与我如何在takeaway.cpp的启动列表中调用gameCore的构造函数有关

我有一个模板化的类(gameCore.h)和一个继承自gameCore的类(takeaway.cpp)vtable错误被称为3次1)在takeaways构造函数中2)takeaways析构函数3)在gameCores构造函数中

我正在使用G ++这里是代码:(我知道它可能看起来很难读,但我已经标记了错误发生的地方)takeaway.h

#ifndef _TAKEAWAY_H_
#define _TAKEAWAY_H_
#include<map>
#include<cctype>
#include<stack>
#include<map>
#include<iostream>
#include<string>
#include<cstdlib>
#include"gameCore.h"
#include<vector>
using namespace std;
class takeaway : public …
Run Code Online (Sandbox Code Playgroud)

c++ linker linker-errors vtable

37
推荐指数
3
解决办法
11万
查看次数

C++ Undefined对vtable和继承的引用

档案啊

#ifndef A_H_
#define A_H_

class A {
public:
    virtual ~A();
    virtual void doWork();
};

#endif
Run Code Online (Sandbox Code Playgroud)

文件Child.h

#ifndef CHILD_H_
#define CHILD_H_

#include "A.h"

class Child: public A {
private:
    int x,y;
public:
    Child();
    ~Child();
    void doWork();
};
#endif
Run Code Online (Sandbox Code Playgroud)

和Child.cpp

#include "Child.h"

Child::Child(){
    x = 5;
}

Child::~Child(){...}

void Child::doWork(){...};
Run Code Online (Sandbox Code Playgroud)

编译器说对vtable有一个未定义的引用A.我尝试了很多不同的东西,但没有一个有效.

我的目标是将类A作为接口,并从头部分离实现代码.

c++ inheritance vtable

29
推荐指数
2
解决办法
8万
查看次数

对`vtable的奇怪未定义引用

我困"undefined reference to vtable..."了一整天。

其实我已经看到很多答案 "undefined reference to vtable..."

例如:

未定义对vtable“交易”的引用

未定义对vtable的引用

https://gcc.gnu.org/faq.html#vtables

未定义对vtable的引用

有些人的问题是忘记编写虚拟函数,而其他人则忘记了将.cpp文件添加到生成目录。但是我想我已经注意到了。

我要执行以下步骤:

  • 我要编译类A_1A_2转到共享库libAA_2源自A_1

A_1.h

#ifndef include_A_1_h
#define include_A_1_h
class A_1
{
public:
    A_1() {}
    virtual ~A_1() {} // not pure-virtual function has defined
    virtual void print() = 0;

private:
};
#endif
Run Code Online (Sandbox Code Playgroud)

A_2.h

#ifndef include_A_2_h
#define include_A_2_h
#include "A_1.h"

class A_2 : public A_1
{
public:
    A_2() {}
    ~A_2() {}
    virtual void print();

private:
}; …
Run Code Online (Sandbox Code Playgroud)

c++ g++

12
推荐指数
1
解决办法
182
查看次数

对vtable的未定义引用

我正在尝试编写一个基本上像indianwebproxy一样工作的Http代理

所以我启动了qtcreator,但是我的一个类无法使用臭名昭着的错误进行编译:undefined reference to vtable for HttpProxyThreadBrowser.我无法弄清楚为什么这样做.我在Stackoverflow上阅读了类似的问题,显然问题是未定义的虚拟方法不纯,但我还没有声明任何虚函数.这是我的课

class HttpProxyThreadBrowser : public QThread
{
public:
    HttpProxyThreadBrowser(QTcpSocket outgoingSocket,QTcpSocket  browserSocket,QObject *parent = 0);
    ~HttpProxyThreadBrowser(){};
    void run();

private:
    QTcpSocket outgoingSocket;
    QTcpSocket browserSocket;

};
Run Code Online (Sandbox Code Playgroud)

我在这里用pastebin定义了这个类,以免给你带来烦恼.不幸的是,我无法找出为什么vtable未定义.请协助.

httpproxythreadbrowser.cpp:5: undefined reference to `vtable for HttpProxyThreadBrowser
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

c++ qt linker-errors vtable

5
推荐指数
3
解决办法
3万
查看次数

未定义的引用vtable

我有一个类afporoills,可以帮助我们的内存管理模块中找到数据.(不要问为什么这么奇怪的名字我不知道)

class afporoills{
    void** test(int pos);
};
void** afporoills::test(int pos){
    int x=(pos<<3)|1023*x;
    void** ret=(void**)x;
    if((int)ret%16) return this.test(pos+1);
    void* (*fp)(float, uint16__t)=x;
    ret=ret+(*fp)(1.0f, (uint16__t)pos);
    return ret;
}
int test(){
    afporoills afporoills14;
    return ((char*) (uint32_t) ((uint32_t) (void*) afporoills14.test(((((uint32_t)))((char*) (void*))1));

}
Run Code Online (Sandbox Code Playgroud)

我一直在

[链接器错误]未定义对'vtable for afporoills`的引用

但我不知道vtable是什么!我没用过一个,为什么会有错误呢?

请帮助我,因为如果我没有摆脱那个错误,我不能继续写那个课程.

我还需要做些什么来使test方法完成?

c++ vtable

3
推荐指数
1
解决办法
6814
查看次数

构造函数和析构函数对 vTable 的未定义引用

我有一个虚拟基类,称为 AbstractHeap。AbstractHeap 有一个虚函数“comp”。它还具有一个(非虚拟)构造函数和析构函数,应由所有已实现的派生类使用。

AbstractHeap由MinHeap继承。它实现了“comp”。它还有一个构造函数,它只调用基本构造函数。

最后,Main.cpp 只是创建了一个 MinHeap 实例。

当我编译程序时,它给我这个错误:

$ rm *.o && make
g++ -std=c++11 -c -g AbstractHeap.cpp
g++ -std=c++11 -c -g Main.cpp
g++ -std=c++11 -g -Wall Main.o AbstractHeap.o -o Main
Main.o: In function `MinHeap::MinHeap(int, int)':
/mnt/c/dev/Data_Structures/Lab7/MinHeap.h:8: undefined reference to `vtable for MinHeap'
/mnt/c/dev/Data_Structures/Lab7/MinHeap.h:8: undefined reference to `vtable for MinHeap'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'Main' failed
make: *** [Main] Error 1
owen@MatrixSword:/mnt/c/dev/Data_Structures/Lab7$ rm *.o && make
g++ -std=c++11 -c -g AbstractHeap.cpp
g++ …
Run Code Online (Sandbox Code Playgroud)

c++ gcc c++11

2
推荐指数
1
解决办法
1950
查看次数

对C++中的非纯虚拟类感到困惑,它们有什么用?

我有一个声明如下的类:

class TestFoo {
public:
    TestFoo();
    virtual void virtualFunction();
    void nonVirtualFunction();
};
Run Code Online (Sandbox Code Playgroud)

我尝试以这种方式实现

TestFoo::TestFoo(){}
void TestFoo::nonVirtualFunction(){}
Run Code Online (Sandbox Code Playgroud)

在编译时返回错误:

undefined reference to vtable for TestFoo
Run Code Online (Sandbox Code Playgroud)

我试过了 :

TestFoo::TestFoo(){}
void TestFoo::nonVirtualFunction(){}
void TestFoo::virtualFunction(){}
Run Code Online (Sandbox Code Playgroud)

编译确定与这些帖子的答案一致:

未定义的vtable参考

未定义的引用vtable

令我困惑的是,我认为声明虚函数的重点在于我不需要定义它.在这个例子中,我不打算创建任何TestFoo实例,而是创建从TestFoo继承的(具体)类的实例.但是,我仍然想为TestFoo的每个子类定义函数nonVirtualFunction.

我不对劲的东西?

谢谢 !

c++ virtual hyperlink vtable

1
推荐指数
1
解决办法
191
查看次数

未定义的vtable引用(C++)

我正在为我的sfml游戏制作一个Entity类,但我无法理解为什么下面的代码无法编译.我收到一个undefined reference to vtable in Entity错误.

这是头文件:

#ifndef ENTITY_H
#define ENTITY_H
#include <string>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Time.hpp>

class Entity
{
public:
        Entity(std::string id, sf::Vector2f position, float rotation );
        virtual ~Entity() = 0;
        virtual sf::FloatRect getBoundingRect() const;
        virtual float getRadius() const;
        void UpdateVelocity(sf::Time);
        void UpdatePosition(sf::Time);
        void Update(sf::Time);
        float getRotation() const;
        sf::Vector2f getPosition() const;
        sf::Vector2f getVelocity() const;
        sf::Vector2f getAcceleration() const;


private:
        std::string mId;
        sf::Vector2f mPosition;
        float mRotation;
        sf::Vector2f mVelocity;
        sf::Vector2f mAcceleration;
};

#endif // ENTITY_H
Run Code Online (Sandbox Code Playgroud)

这是cpp文件:

#include "../include/Entity.h" …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
697
查看次数

'在构造函数/ Desconstructor的情况下'未定义对vtable的引用'

当我用c ++ 11和发布模式练习clang ++中的多态时,我得到了2个'对vtable的未定义引用'的错误.以下是我的代码的一些部分.

#include <armadillo>
typedef float CHOSENONE;
typedef std::vector<std::vector<CHOSENONE> > fVect2d;
typedef std::vector<CHOSENONE> fVect;
class CfSubSet {
    private:
        fmat m_Data;
        frowvec m_Label;
        int m_NumInstances, m_NumFeatures ;
    public:
        CfSubSet(){
            cout<<"hello! \n" <<endl;
            m_NumInstances = 0;
            m_NumFeatures = 0;
            m_Data.zeros();
            m_Label.zeros();
        }
        CfSubSet(int iNumInstances, int iNumFeatures):m_NumInstances(iNumInstances),m_NumFeatures(iNumFeatures){
            m_Data.resize(iNumInstances,iNumFeatures);
            m_Label.resize(iNumInstances);
        }
        ~CfSubSet(){
            m_Data.reset();
            m_Label.reset();
        }
        inline int getNumInstances(){return m_NumInstances;};
        inline int getNumFeatures(){return m_NumFeatures;};
        inline fmat& getData(){return m_Data;};
        inline fmat& getLabel(){return m_Label;};
};

class CData
{
    protected:
        CfSubSet * m_Test;
        CfSubSet * m_Train; …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism inheritance c++11

0
推荐指数
1
解决办法
676
查看次数