throw声明中的循环依赖 [英] Cyclic dependency in throw declaration
本文介绍了throw声明中的循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法得到以下内容来编译
展开 | < span class =codeLinkonclick =selectAll(this);>选择 | 换行 | 行号
解决方案
你不能从struct m声明中抛出一个m对象。此时,编译器不知道m对象是什么。比如,是否有默认构造函数,或者更多数据成员等。
因此它不知道要生成什么代码。也就是说,直到它到达结构声明的结尾。
你将需要抛出一个m *。
自编译器已经看过struct m,这是允许m *的足够信息。
嗨弱点,
感谢您的回复。我知道这个设计问题应该有一个简单的解决方法。你建议的解决方案非常简单,我只是抛出指向结构而不是实际对象的指针。
温馨的问候,
Gaura
对不起,伙计们。我实际上并没有尝试使用包含的更改来编译上面的代码。我们认为可行的改变是:抛出指向''struct m'的指针而不是抛出''struct m''本身的实例。更清楚我想说的是下面的代码
展开 | 选择 | Wrap | 行号
Hi,
I am unable to get the following to compile
Expand|Select|Wrap|Line Numbers解决方案You cannot throw an m object from inside the struct m declaration. At this point the compiler does not know what an m object is exactly. Like, is there a default constructor, or maybe more data members, etc..
As a result it doesn''t know what code to generate. That is, not until it reaches the end of the struct declaration.
You will need to throw an m*.
Since the compiler has seen "struct m", that is enough information to allow an m*.
Hi weaknessforcats,
Thanks for your kind reply. I knew that there should be a simple workaround for this design problem. The solution that you suggested is very simple, I just throw a pointer to the struct instead of the actual object.
Warm Regards,
Gaura
Hi,
Sorry folks. I hadn''t actually tried compiling the above code with the change included. The change that we thought would work was: throwing a pointer to ''struct m'' rather than throwing an instance of ''struct m'' itself. To be more clear what I am trying to say is that the code below
Expand|Select|Wrap|Line Numbers
这篇关于throw声明中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆