设为首页 加入收藏

TOP

C++函数与Java函数对比初识
2014-11-23 22:22:19 来源: 作者: 【 】 浏览:9
Tags:函数 Java 对比 初识

1. 在java中,假如我要实现一个函数getHeight(int height)返回的是传入的height


1). 在A.java文件中声明和定义函数的实现,代码如下:


public class A
{


public int getHeight(int height)
{
return height;
}
}


2).在B.java中提供主入口函数,然后调用A类中的函数getHeight,代码如下:


public class B
{


/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub


A a = new A();
a.getHeight(180);
}


}


2.对比在C++中实现同样的函数:


1). 在a.h文件中声明类和函数,实现如下:


class A
{
pubic:
int get_height(int height);
};


2).在 a.cpp文件中的进行函数的定义,代码如下:


#include "a.h"


int A::get_height(int height)
{
return height;
}


3).在 main.cpp文件中实现调用函数get_height(int height),代码如下:


#include "a.h"


void main()
{
A a;
a.get_height(180);
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android中的Parcelable接口 下一篇Hibernate一对多和多对一双向关联..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: