c++ - 继承 - 符号未定义 Objective-C++

标签 c++ objective-c xcode linker objective-c++

快速提问...这只是我对继承的误解,所以应该很快解决(我使用的是 objective-c++)。如果问题已经解决,我会取消这个问题......我找不到它因此我的帖子:

我有以下内容:

基础.h文件

#ifndef BASE_H
#define BASE_H

class Base {
public:
    // Virtual Constructor
    Base() {}; 
}
#endif

派生.h文件

// Derived.h
#ifndef DERIVED_H
#define DERIVED_H

#include "Base.h"

class Derived : public Base {
public:
    Derived();
}
#endif

派生.cpp文件

// Derived.cpp
#include "Derived.h"

Derived::Derived() {
    // Do construction here!
}

Wrapper.mm 文件

// Wrapper.mm
#include "Derived.h"

- (id)init {
    if (self = [super init]) {
        Base *b = new Derived();     // Cannot compile?
    }
}

我从 Wrapper.o 中的 -[Wrapper init] 引用的 "Derived::Derived()"得到一个未定义的错误;找不到体系结构 arm64 的符号。我该如何解决?谢谢!

最佳答案

您没有链接编译 Derived.cpp 时生成的 .o 文件。当您编译 Wrapper.mm 文件以创建可执行文件时,只需将 Derived.o 添加到编译器参数的末尾,您应该会很好(尽管我以前从未听说过 obj-c++)

关于c++ - 继承 - 符号未定义 Objective-C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40117758/

相关文章:

iphone - 图像数据的 Base64 解码问题-iphone

ios - TTTAttributedLabel 链接检测无法使用 Storyboard

objective-c - 刷新 UITableview 导致 EXC_BAD_ACCESS 错误

xcode - CoreBluetooth[WARNING] 没有恢复标识符,但委托(delegate)实现

c++ - 未解析的外部符号 ...QueryInterface

c++ - 过时函数的标准 COM HRESULT 是什么?

c++ - Linux 二进制兼容性

未找到 C++ python 库。代码块 GNU GCC

iphone - colorWithPatternImage 和 setCornerRadius 问题

ios - Xcode Swift 委托(delegate),VC 实例化时新值被覆盖