Re: obj function hello()
- From: "gert" <gert.cuykens@xxxxxxxxx>
- Date: 8 Feb 2007 16:43:24 -0800
On Feb 9, 1:30 am, Ian Collins <ian-n...@xxxxxxxxxxx> wrote:
You can't have functions in structs in C. What yo can have is function
pointers:
struct Obj {
int someInt;
int (*someFn)(void);
};
But you have to assign a function address to the pointer for each
instance of Obj.
So this means i have to do something like this then ?
#include <stdio.h>
struct obj {
char *data = ''
int (*add)(void);
}
function add(char *value){
obj.data += value;
}
obj function hello(){
obj.data = 'hello';
return obj;
}
void main(){
test = hello();
test.add('world');
printf(test.data);
}
.
- Follow-Ups:
- Re: obj function hello()
- From: Christopher Benson-Manica
- Re: obj function hello()
- From: Nick Keighley
- Re: obj function hello()
- From: Ian Collins
- Re: obj function hello()
- References:
- obj function hello()
- From: gert
- Re: obj function hello()
- From: Ian Collins
- Re: obj function hello()
- From: gert
- Re: obj function hello()
- From: Ian Collins
- obj function hello()
- Prev by Date: Re: IS this a proper way of freeing memory with free()
- Next by Date: Re: IS this a proper way of freeing memory with free()
- Previous by thread: Re: obj function hello()
- Next by thread: Re: obj function hello()
- Index(es):
Relevant Pages
|