不知道有没有人了解 Android 的 class sp?
在源码中我常看到下面用法
sp <Camera> c = new Camera(int)
new 在 c++中就是配置内存然后回传内存位址,但 c 又是一个物件。事实上,我根
本搞不清楚 android 的这个 c 代表的是什么。一开始我以为他是一个指标,去接new
出来的。但好像不是这么回事,因为我写了一个小程式去试
#include<iostream>
using namespace std;
template<typename T>
class sp{
public:
sp(T *other){
cout<<"This is the first constructor"<<endl;
}
sp(const sp<T>& other){}
};
class myClass{
public:
myClass():a(0){}
int getA(){
return a;
}
private:
int a;
};
int main(){
sp<myClass> c = new myClass();
cout<<c->sp()<<endl;
}
出来的讯息意思是说 c 是一个物件,不是一个指标~
[Error] base operand of '->' has non-pointer type 'sp<myClass>'
应该是 android 的 class sp 有写些动作.....,小弟底子差,看了几天也问了板友只
知道
sp<myClass> c = new myClass()
这个用法会用到 c++ 的 copy initialization,以及我知道他会 call 到 class sp 内
的 sp(T *other) 建构子, 我不知道这个 c 代表什么?
sp<myClass> c = new myClass() 这个式子
会动用到 class sp 内的哪一个 operater overload 还是 不会?
~"~
希望能从各位牛人汲取到一点建议
谢谢