我正在尝试在'如何做C函数指针工作'问题中侦听的示例之一,并且我正在用于体系结构x86_64错误的未定义符号中。体系结构x86_64函数指针的未定义符号
完整的日志:
Undefined symbols for architecture x86_64:
"_getString", referenced from:
_newString in main-3adb06.o
"_lengthString", referenced from:
_newString in main-3adb06.o
"_setString", referenced from:
_newString in main-3adb06.o
ld: symbol(s) not found for architecture x86_64
的代码我使用:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct String_Struct* String;
struct String_Struct
{
char* (*get)(const void* self);
void (*set)(const void* self, char* value);
int (*length)(const void* self);
};
char* getString(const void* self);
void setString(const void* self, char* value);
int lengthString(const void* self);
String newString();
String newString()
{
String self = (String)malloc(sizeof(struct String_Struct));
self->get = &getString;
self->set = &setString;
self->length = &lengthString;
self->set(self, "");
return self;
}
int main(){
String s1 = newString();
s1->set(s1, "Hello, World!");
}
(在相同的答案)。
你真的没有getString ...我想你忘了添加/写入这些功能? – xosp7tom
你能否提供一个'C函数指针如何工作'的链接?(它可能已被重命名/删除?) – pseyfert
http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work – Teun