C++中模板类对象创建

C++中模板类对象创建,第1张

#include
#include
using namespace std;

class A{

};

class B : public A {

};

template
class shared_ptr{
public:

template
shared_ptr(Y y){
    cout<<"shared_ptr default consturctor 1"<
shared_ptr(shared_ptr const& r){
    cout<<"shared_ptr consturctor"<
shared_ptr& operator=(shared_ptr const& r)
{
    
}

};

转自此链接中详细分析了,创建对象时的各种带括号和不带括号的情况;其中就讲述了,
如下main函数中shared_ptr c(); //什么也不输出,但是没有任何打印的原因。这里是一个函数;
https://www.cnblogs.com/lvvou/p/14974734.html

int main() {
B b;
shared_ptr c;//输出shared_ptr default consturctor 2
shared_ptr c(); //什么也不输出,但是没有任何打印,因为相当于定义了一个返回值shared_ptr,且不带参数的函数
function f(shared_ptr c()); //没有问题
//shared_ptr b;
//shared_ptr a(b);

return 0;

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/2991826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-23
下一篇 2022-09-23

发表评论

登录后才能评论

评论列表(0条)

保存