我正在创建一个示例静态库以在我的 iOS 应用程序中使用,但是,在调用静态库的方法时,我遇到了链接器错误:
Undefined symbols for architecture arm64:
"_doMath", referenced from:
  _doMathInterface in libTestMain.a(Test.o)
 (maybe you meant: _doMathInterface)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
这是静态库的结构:
我有一个头文件 Test.h:
#import <Foundation/Foundation.h>
@interface Test : NSObject
int doMathInterface(int a, int b);
@end
Run Code Online (Sandbox Code Playgroud)
及其实现 Test.m :
#import "Test.h"
#include "PaymentAPI.h"
@implementation Test
int doMathInterface(int a, int b){
    return doMath(a, b);
}
@end
Run Code Online (Sandbox Code Playgroud)
在 PaymentAPI.h 中:
#ifndef PaymentAPI_h
#define PaymentAPI_h …Run Code Online (Sandbox Code Playgroud) 我正在学习 C++,但无法理解与指针相关的某些行为。
我有一个简单的自定义对象,如下所示:
class Human {
public:
       //constructor here
private:
       std::string name;
       std::string address;
}
Run Code Online (Sandbox Code Playgroud)
另一个具有指向人类指针的实例变量类型的自定义对象:
class property {
public:
       Human * ppl;//pointer to the above human object
}
Run Code Online (Sandbox Code Playgroud)
并运行这段代码:
Human * human = new Human("Mark", "address");// pointer address 0x123456 for example
Property * property = new Property();
property->ppl = human;//pass the pointer to property's instance variable 
delete human; 
human = NULL;//after deleting and setting it to NULL property.ppl still points to 0x123456
Run Code Online (Sandbox Code Playgroud)
运行上面的代码后,property下的ppl实例变量仍然指向原来的内存地址,但是里面的内容(name和address)都被清除了(现在是空字符串),我想知道为什么会这样?既然我传递了原始指针,为什么删除它并将其设置为NULL后,它仍然指向一个内存地址,但它的内容已被清除?
仅供参考:我使用 XCode 作为调试 IDE 和 C++11