可以将朋友函数用作构造函数 [英] can a friend function be used as constructor

查看:77
本文介绍了可以将朋友函数用作构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它只是它.... !!!



回复一个或多个例子.....简单但

its just it....!!!

reply with a one or more examples.....simple though

推荐答案

这是可能但没有意义,因为朋友的功能是外部的,但必须调用类代码。



界面将是喜欢:

It is possible but makes no sense, because a friend function is external but must call class code.

The interface would be like:
MyClass* friendConstructor();





你应该学习写干净的代码,避免这么棘手的东西。您最好利用您的时间并学习基础知识。生命太短暂无法抹去。 ; - )



You should learn to write "clean code" and avoid so tricky stuff. You better use your time and learn the basics. Life is too short to waiste it. ;-)


不作为普通构造函数。

如果 C ++中命名的构造函数习惯 [ ^ ]任何意义都取决于你。

问候

Andi
Not as a plain constructor.
If the Named Constructor Idiom in C++[^] makes any sense is up to you.
Regards
Andi


这篇关于可以将朋友函数用作构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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