
即就像是
Class Baz{ const Foo f; const bar b; Baz(Paramaters p):temp(p),f(p,temp),b(p,temp){ //temp is an instance of Something // But NOT A member of Baz // Whatever }} 代替
Class Baz{ Foo f; bar b; Baz(Paramaters p){ Something temp(p); f = Foo(p,temp) b = bar(p,temp) }} 要么
Class Baz{ Foo f; bar b; Baz(Paramaters p,Something s):f(p,s),s){ }}解决方法 在C 11中,您可以使用委托构造函数: class Baz{ const Foo f; const bar b; Baz(Paramaters p) : Baz(p,temp(p)) { } // Delegates to a private constructor // that also accepts a Somethingprivate: Baz(Paramaters p,Something const& temp): f(p,temp) { // Whatever }}; 总结 以上是内存溢出为你收集整理的C临时变量在启动列表中全部内容,希望文章能够帮你解决C临时变量在启动列表中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)