我的母语是C##, 所以当我开始使用C++时, 我想为 C# 中的图书馆用户创建获取/设置食糖语法。
于是我写了...
template<typename T>
class GetProperty
{
private:
T (*get)();
public:
GetProperty(T (*get)())
{
this->get = get;
}
operator T()
{
return get();
}
template<typename S, typename T>
GetProperty<S> operator=(GetProperty<T> fool)
{
throw 0;
}
};
然后,为了使用这个,我写了代码:
template<typename T>
class Vector
{
private:
struct LinkItem
{
public:
T* Item;
LinkItem* Next;
GetProperty<int> Length (&getLength);
LinkItem(T* Item = NULL, int length = 1, LinkItem* Next = NULL)
{
this->Item = Item;
this->length = length;
this->Next = Next;
}
LinkItem& operator =(LinkItem rhs)
{
this->Item = rhs.Item;
this->length = rhs.length;
this->Next = rhs.Next;
return *this;
}
private:
int length;
int getLength()
{
return length;
}
};
LinkItem* current;
.
.
.
};
However, the C/C++ addition on Netbeans (I believe this is the g++ compiler) claims I am instantiating GetProperty with no type.
According to a Google search, this happens if someone forgets a using statement, or to include a header, etc.
But int is a primitive, so this can t be.
What s going on?