class time24;
class time12
{
operator time24()
{
...
return time24(temp) // error
}
}
class time24
{
...
};
错误 C2440:“”:无法从“int”转换为“time24”
我还能如何返回对象来克服这个错误
最佳答案
在实现文件中将实现移动到类定义之后:
//header.h
class time24;
class time12
{
operator time24();
}
class time24
{
...
};
//implementation.cpp
#include "header.h"
time12::operator time24()
{
return time24(temp) // error
}
我假设您打算实现 operator time24()
。
关于c++ - 如果稍后定义返回对象的类,我应该如何从转换函数返回对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10172718/