【发布时间】:2010-06-19 03:54:19
【问题描述】:
我有一个对象,例如,我想在另一个类中调用它的函数
class smo {
int spoon = 10;
smo() {
}
int get_spoon() {
return spoon;
}
}
class boat {
boat() {
}
print_smo(Object test) {
test.get_spoon();
}
}
它告诉我函数 get.spoon() 不存在。该错误是有道理的,因为该对象尚未创建,因此无法调用该函数,但它会在它运行时存在,并且我已将 smo 类型的适当对象传递给它。
【问题讨论】:
-
重新格式化的代码;如果不正确,请恢复。