I am trying one of the examples listened in the 'how do function pointers works in C' question, and I am stucking in a Undefined symbols for architecture x86_64 error.
The full log:
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
The code I used:
#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!");
}
(the same as in the answer).