有基类CValue,继承类CIntegerValue,和CFloatValue,
encodeValue(CValue val)
{
CString cs;
int type; //val=(CValue)val;
传进来的val,有时是CIntegerValue类型,有时是CFloatValue类型,
type=val.type;
if(type==INTEGER)
{
CIntegerValue intVal;
怎样将val转换为intVal呢?????????????
}
encodeValue(CValue val)
{
CString cs;
int type; //val=(CValue)val;
传进来的val,有时是CIntegerValue类型,有时是CFloatValue类型,
type=val.type;
if(type==INTEGER)
{
CIntegerValue intVal;
怎样将val转换为intVal呢?????????????
}
解决方案 »
- tcp连接中什么时候会发RST报文?
- 真心求解答,关于研发与测试
- 色盲可以学图形图像处理吗
- GetWindowText的深层问题
- CoGetInterfaceAndReleaseStream 得到的指针为什么不能使用?
- 怎样实现菜单的切换?
- 如何用srand()和rand()产生若干0-1之间的随机数呢?
- OnContextMenu
- 如何在CMainFrame中却得CDialogBar(从对话框资源模板)创建的对话框的HWND?
- 怎么用vc6.0抓取百度百科词库中所有词语?
- 菜鸟请教:关于打印RMB符号,为什么这样写不行啊?请指点……
- 高手给指点一下,是不是CString的Left不好使了??
=>
encodeValue(const CValue& val)
并且CValue应该虚化,如果没有需要virtual的method,可以考虑virtual destructorCIntegerVal intVal=static_cast<CInterVal>(val);
encodeValue(CValue *pval)
{
type=val.type;
if(type==INTEGER)
{
CIntegerValue *intVal = dynamic_cast<CIntegerValue *>pval;
}
}如果使用你原来的传值方法,进入函数后对象已经被down cast成CValue类型了,并且这个CValue是构建在堆栈上的临时对象,不能cast成CIntegerValue或CFloatValue
warning C4541: 'dynamic_cast' used on polymorphic type 'class CValue' with /GR-; unpredictable behavior may result
这是使用dynamic_cast,不知道是什么意思?