
C++编译一直出现这样的错误,error C2039: 'setNo' : is not a member of 'Rectangle<ElemType>'
代码如下:template<typenameElemType>classRectangle{public:classRectangleNo{public:intno;};...
代码如下:
template<typename ElemType>
class Rectangle
{
public:
class RectangleNo
{
public:
int no;
};
Rectangle();
Rectangle(const Rectangle &otherD);
virtual ~Rectangle();
void setNO(int i);
protected:
ElemType length;
ElemType width;
RectangleNo myNo;
};
template <typename ElemType>
Rectangle<ElemType>::Rectangle()
{
length=width=0;
cout<<" 自动调用构造函数"<<endl;
}
template <typename ElemType>
Rectangle<ElemType>::Rectangle(const Rectangle<ElemType>& otherD)
{
length=otherD.length;
width=otherD.width;
myNo=otherD.myNo;
cout<<" 自动调用拷贝初始化构造函数初始化为("length<<","<<width<<")"<<endl;
}
template<typename ElemType>
Rectangle<ElemType>::~Rectangle()
{
cout<<"\n 第"<<myNo.no<<"个长方形对象("<<length<<","<<width<<")生存期结束!"<<endl;
}
template <typename ElemType>
void Rectangle<ElemType>::setNo(int i)
{
myNo.no=i;
}
他说setNo不是Retangle的成员。可是我set明明就声明在这个类里面的啊!求大神解答。多谢。因为没有多少财富值了,不够悬赏10了,只能悬赏5,求大神解答 展开
template<typename ElemType>
class Rectangle
{
public:
class RectangleNo
{
public:
int no;
};
Rectangle();
Rectangle(const Rectangle &otherD);
virtual ~Rectangle();
void setNO(int i);
protected:
ElemType length;
ElemType width;
RectangleNo myNo;
};
template <typename ElemType>
Rectangle<ElemType>::Rectangle()
{
length=width=0;
cout<<" 自动调用构造函数"<<endl;
}
template <typename ElemType>
Rectangle<ElemType>::Rectangle(const Rectangle<ElemType>& otherD)
{
length=otherD.length;
width=otherD.width;
myNo=otherD.myNo;
cout<<" 自动调用拷贝初始化构造函数初始化为("length<<","<<width<<")"<<endl;
}
template<typename ElemType>
Rectangle<ElemType>::~Rectangle()
{
cout<<"\n 第"<<myNo.no<<"个长方形对象("<<length<<","<<width<<")生存期结束!"<<endl;
}
template <typename ElemType>
void Rectangle<ElemType>::setNo(int i)
{
myNo.no=i;
}
他说setNo不是Retangle的成员。可是我set明明就声明在这个类里面的啊!求大神解答。多谢。因为没有多少财富值了,不够悬赏10了,只能悬赏5,求大神解答 展开
2个回答
展开全部
void Rectangle<ElemType>::setNO(int i)
{
myNo.no=i;
}
应该是你最后那域运算符没注意“::”
我在我这里重写了::通过了编译
{
myNo.no=i;
}
应该是你最后那域运算符没注意“::”
我在我这里重写了::通过了编译
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询