模板实例化中的循环依赖 [英] cyclic dependency in template instantiation

查看:74
本文介绍了模板实例化中的循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在搜索我的问题的解决方案时,我偶然发现了奇怪的重复模板模式,请参阅链接


这是模式的样子:

展开 | 选择 | Wrap | 行号

解决方案




对不起,GNU报告的最后一个错误编译器是由于缺少分号:

展开 | 选择 | Wrap | 行号


我不认为只使用两个类就可以这样做。如果你想访问一些派生类方法或变量,那将是可能的。在基类中使用wiki文章中描述的static_cast,但是因为你要访问一个派生类类型,在你使用的基类之前必须知道哪个定义,所以我认为最好将派生类成员解耦在将在struct / class y之前定义的类中。也许这样的事情可能会做你想要的:

展开 | 选择 | Wrap | 行号


将enum移出struct x

Hi,

When searching for a solution to my problem I stumbled upon ''Curiously Recurring Template Pattern'' see link.

This is how the pattern looks:

Expand|Select|Wrap|Line Numbers

解决方案

Hi,

I am sorry, the last error reported by the GNU compiler is due to a missing semicolon on the line:

Expand|Select|Wrap|Line Numbers


I don''t think it''s possible to do so using only two classes.It would be possible if you were wishing to access some of the derived class methods or variable in base class by using the static_cast as described in wiki article, but since you are after to access a derived class type which definition must be known prior to the base class you are using then I think it''s best to decouple derived class members in a class which will be defined before your struct/class y is. Perhaps something like this might do what you want:

Expand|Select|Wrap|Line Numbers


Move the enum out of struct x


这篇关于模板实例化中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆