如何在c中编写面向对象的程序 [英] How to write object oriented program in c
问题描述
如何在c中编写面向对象的程序?举个例子......
How to write a object oriented program in c? give me one example....
推荐答案
" SSG" < SS **** @ gmail.com>写道:
"SSG" <ss****@gmail.com> writes:
如何在c中编写面向对象的程序?给我一个例子......
How to write a object oriented program in c? give me one example....
#include< stdio.h>
int main(无效)
{
puts(面向对象程序);
返回0;
}
>
假设'不是你的想法,尝试搜索这个
新闻组;其他人最近也在这里提出了同样的问题。
-
Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
#include <stdio.h>
int main(void)
{
puts("a object oriented program");
return 0;
}
Assuming that''s not what you had in mind, try searching this
newsgroup; others have asked the same question here recently.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
#include< stdio.h>
struct A
{
public:
A(){printf(" A :: constructor \\\
"); }
~A(){printf(" A :: destructor \ n"); }
void print(){printf(" A :: print \\\
"); }
};
int main(int argc,char * argv [])
{
A a;
a.print();
printf(" Hello World!\ n");
返回0;
}
使用struct,只有从类到结构的区别是所有方法和结构中的
变量是公共的默认....
#include<stdio.h>
struct A
{
public:
A(){ printf(" A:: constructor \n"); }
~A(){ printf(" A:: destructor \n"); }
void print(){ printf(" A::print \n"); }
};
int main(int argc, char* argv[])
{
A a;
a.print();
printf("Hello World!\n");
return 0;
}
use struct, only difference from class to struct is all the methods and
variables in struct are public by default ....
lampard写道:
lampard wrote:
#include< stdio.h>
struct A
{
public:
#include<stdio.h>
struct A
{
public:
语法错误。 BOOM。
-
Chris" electric hedgehog" Dollin
Stross赢了一个!法拉赢了一个! Langford赢了两个!
Syntax error. BOOM.
--
Chris "electric hedgehog" Dollin
Stross won one! Farah won one! Langford won TWO!
这篇关于如何在c中编写面向对象的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!