快速提问...这只是我对继承的误解,所以应该很快解决(我使用的是 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/