obj函数hello() [英] obj function hello()

查看:130
本文介绍了obj函数hello()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>


obj函数hello(){

struct obj = {char * data =''hello'' }

obj.add = obj_add(obj);

返回obj;

}


void function obj_add(obj){

obj function add(value){

obj.data + = value;

return obj;

}

}


void main(){

test = hello();

test.add(''world'');

printf(test.data);

}


我不太了解c我希望上面的代码指出

我想做什么?

#include <stdio.h>

obj function hello(){
struct obj = { char *data = ''hello''}
obj.add = obj_add(obj);
return obj;
}

void function obj_add(obj){
obj function add(value){
obj.data += value;
return obj;
}
}

void main(){
test = hello();
test.add(''world'');
printf(test.data);
}

I don''t know much c and i was hoping the code above was pointing out
what i am trying to do ?

推荐答案

gert写道:
gert wrote:

#include< stdio.h>


obj function hello(){

struct obj = {char * data =''hello''}

obj.add = obj_add(obj);

return obj;

}


void function obj_add(obj) {

obj函数add(value){

obj.data + = value;

return obj;

}

}


void main(){

test = hello();

test .add(''world'');

printf(test.data);

}


我不喜欢我知道很多c,我希望上面的代码指出

我想做什么?
#include <stdio.h>

obj function hello(){
struct obj = { char *data = ''hello''}
obj.add = obj_add(obj);
return obj;
}

void function obj_add(obj){
obj function add(value){
obj.data += value;
return obj;
}
}

void main(){
test = hello();
test.add(''world'');
printf(test.data);
}

I don''t know much c and i was hoping the code above was pointing out
what i am trying to do ?



你试图写几乎,但不完全,不像

C.它更像是JavaScript。


你不能将函数(或其他任何东西)绑定到结构体在运行时用C.


-

Ian Collins。

You are attempting to write something almost, but not entirely, unlike
C. It is more like JavaScript.

You can''t bind functions (or anything else) to structs at runtime in C.

--
Ian Collins.


我实际上是从python开始的。我试图找出如何制作

a结构,其中包含在结构中定义的数据和函数?
i started from python actually. I was trying to figure out how to make
a struct that has data and functions defined in the struct it self ?


gert写道:
gert wrote:

i实际上是从python开始的。我试图找出如何制作

a结构,其中包含在结构中定义的数据和函数?
i started from python actually. I was trying to figure out how to make
a struct that has data and functions defined in the struct it self ?



请保持上下文你回复了。


你不能用C语言中的结构函数。你可以拥有的是函数

指针:
< br $>
struct Obj {

int someInt;

int(* someFn)(void);

};


但是你必须为每个

Obj实例的指针分配一个函数地址。


-

Ian Collins。

Please keep the context you are replying to.

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.

--
Ian Collins.


这篇关于obj函数hello()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆