C/C++与Java函数重载区别!
#include <iostream>
using namespace std;
class Base {
public:
virtual void fn(int x) {
cout << "In Base class, int x = " << x << endl;
}
};
class SubClass : public Base {
public:
// 函数的重载,这样的重载方式,在Java中能行,在C/C++中却不行
virtual void fn(float x) {
cout << "In SubClass, float x = " << x << endl;
}
};
void test(Base& b) {
int i = 1;
b.fn(i);
float f = 2.0;
b.fn(f);
}
int main() {
Base bc;
SubClass sc;
cout << "Calling test(bc)\n";
test(bc);
cout << "Calling test(sc)\n";
test(sc);
return 0;
}
Calling test(bc)
In Base class, int x = 1
In Base class, int x = 2
Calling test(sc)
In Base class, int x = 1
In Base class, int x = 2
运行成功(总计时间: 312毫秒)
注意,都是调用的父类中的函数.
package cn.vicky;
public class MyTest {
public void add(int i) {
System.out.println("in parent");
}
public static void main(String[] args) {
MyTest2 m2 = new MyTest2();
m2.add(1);
m2.add(1.1);
}
}
class MyTest2 extends MyTest {
public void add(double i) {
System.out.println("in child");
}
}
in parent
in child
Java却可以区分...
相关文档:
使用Runtime.getRuntime().exec()方法可以在java程序里运行外部程序.
该方法有6个可访问版本:
1.exec(String command)
2.exec(String command, String envp[], File dir)
3.exec(String cmd, &n ......
Flex 和C++ 之间传输结构体数据
一直想试验用结构体传数据
但是Flex 和C++ 的类型所占的字节数有时不一样
如int 在C++中站2个字节,而在Flex中占4个字节。
转换比较麻烦。
最后决定用XML进行传输
然后两边都加一个XML 解析和封装类。
C++ 端使用的tinyXML 类
Flex直接使用自己带的 E4X 类
Flex代码如下
&nb ......
xml文件如下 配置功能开关
<Configurations>
<Samples>true</Samples>
<Excepts>true</Excepts>
<CheckFace>false</CheckFace>
<ThumbNail>false</ThumbNail>
&nbs ......
一、一个经过编译的C/C++的程序占用的内存分成以下几个部分:
1、栈区(stack):由编译器自动分配和释放 ,存放函数的参数值、局部变量的值等,甚至函数的调用过程都是用栈来完成。其操作方式类似于数据结构中的栈。
2、堆区(heap) :一般由程序员手动申请以及释放, 若程序员不释放,程序结束时可能由OS回收 ......
---------------------------------------------------
名 等价值 含 义
BLACK 0 黑
BLUE 1 ......