C++getter函数返回0
C++ - getter function returns 0?
类:
class Process
{
public:
void setTime(int temp);
int getTime();
private:
int myTime;
}
的功能
Process::Process()
{
myTime = 0;
}
void Process::setTime(int temp)
{
myTime = temp;
}
int Process::getTime()
{
return myTime;
}
Main只有Process对象,并设置一个数字和get。我和几个朋友一直在试图弄清楚为什么get函数返回零。
实际的代码在我的另一台电脑上,我现在无法访问它。
如果有帮助的话,我会在一段时间内做一些事情。有什么想法吗?
我认为您需要在类本身内部定义构造函数,因为变量是私有的。。或者尝试使用this.myTime..,或者可能是因为您在set之前调用了get方法。。。
相关文章:
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 接收和返回函数指针的函数指针的类型?
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- C++函数链返回函数
- 返回函数指针的函数的签名
- 由于值返回函数中的错误,程序无法编译.它说未声明的标识符
- 非常量引用返回函数在常量值返回函数上用作 r 值
- 如何在 C++ 中从 void 返回函数访问变量
- 返回函数中带有 2 个可选 ctor 的对象
- 如何在 c++ 中返回函数的结构向量
- 返回 C++ 函数中的引用
- 使用向量时,当返回函数更改时,无法看到输出
- 如何在递归中使用返回函数
- 返回函数模板的类型C++作为第二个模板参数
- 为什么静态指针返回函数中有一个"静态"键?
- 递归返回函数,在特殊情况下不返回
- 从类返回函数
- 从类成员函数返回函数指针
- 从返回函数中推断不存在的模板参数