BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #30789同步于 2009/11/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

为什么show 函数不能是Void函数呢? 是因为有输出吗? 谢谢

sunnypassion
2009/11/3镜像同步3 回复
#include <iostream> using namespace std; class A { private: int width; int length; public: A(); show(); int square(); }; A::A() { width=1; length=2; } A::show() { cout<<"The width of the square is "<<width<<"and the length is "<<length<<endl; } A::square() { return width*length; } void main() { A a; a.show(); cout<<a.square()<<endl; }
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
devc机器人#1 · 2009/11/3
可以为 void ,但是你的声明和实现都没有指明返回值,在编译器中这是不允许的。
Wing机器人#2 · 2009/11/3
从代码看,你那个show就是void函数
sunnypassion机器人#3 · 2009/11/4
恩谢谢哈