免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2011 | 回复: 2
打印 上一主题 下一主题

关于vc下RTTI的disable问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-30 15:26 |只看该作者 |倒序浏览
在用动态类型转换时需要配合RTTI,vc下好象默认disabled,大多说法在"roject Settings/C++/C++ Language",可却找不到有如是设置项,ps:我用的是vc++6(cn),Inter compier8

附错误信息:error #259: run-time support for RTTI is disabled
    TextBox& ct1 = dynamic_cast<TextBox&>;(ct);

论坛徽章:
0
2 [报告]
发表于 2005-04-30 15:45 |只看该作者

关于vc下RTTI的disable问题

就这么说好了,下面一段测试程序运行没问题的告诉我你如何配置rtti参数:
#include <iostream>;
#include <stdexcept>;
#include <typeinfo>;

using namespace std;

class control
{
public:
            virtual void foo() {}
};

class TextBox : public control {};
class EditBox : public TextBox {};
class Button  : public control {};

void Paint(control& ct)
{
            try
            {
                        TextBox& ct1 = dynamic_cast<TextBox&>;(ct);
                        cout<<"aint TextBox successful!"<<endl;
            }
            catch(bad_cast)
            {
                        cout<<"Can't Paint TextBox! error!\a"<<endl;
            }
}

int main()
{
            control ct;
            Paint(ct);

            Button bt;
            Paint(bt);

            TextBox tb;
            Paint(tb);

            EditBox ed;
            Paint(ed);

            return 0;

}

论坛徽章:
0
3 [报告]
发表于 2005-05-06 13:45 |只看该作者

关于vc下RTTI的disable问题

现在手头只有vs2003,这是编译的错误信息
warning C4541: 'dynamic_cast' used on polymorphic type 'control' with /GR-; unpredictable behavior may result
在上面按F1就能够在MSDN中查到:
identifier' used on polymorphic type 'type' with /GR-; unpredictable behavior may result

You tried to use a feature that requires run-time type information without enabling run-time type information. Recompile with /GR.

但是你用的是intel的编译器,估计就得看他的编译选项了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP