# include<stdio.h>
# include <stdlib.h> //atoi
# include <string.h> //strlen
# include <stdint.h> //uint64_t
#include<iostream>
#include<memory> //shared_ptr
using namespace std;
class A{
public:
template<class T> void sumA(T a ,T b,std::shared_ptr<int>* tensor);
A(){
printf("this is a construc function!\n");
}
};
template<> void A::sumA<int>(int a,int b,shared_ptr<int>* tensor){
printf("the sum of A is %d\n",a+b);
*tensor = std::make_shared<int>(5);
}
int main(){
A a;
int b=10;
shared_ptr<int>tensor;
a.sumA<int>(1,2,&tensor);
cout<<"share_ptr:"<<*tensor<<endl;
return 0;
}
输出:
this is a construc function!
the sum of A is 3
share_ptr:00871244
请按任意键继续. . .