[cpp] Re: Cpp Digest, Vol 31, Issue 12

shihui shihui at hyron.com
Tue Oct 17 16:51:33 CST 2006


这个问题我也遇到过,好像VC和Gcc报的错误还是不一样的。

不过ling的source好像

/*template<class T>
Array1D Array2D<T>::operator[](int index)
{
 return a.array[index];
}*/

/*template<class T>
const Array1D Array2D<T>::operator[] (int index) const
{
 return array[index];
}*/

和声明是不一致的。声明里是返回引用,而且Array1D也要写成
Array2D<T>::Array1D吧。

很头痛的问题啊,总之写在class里就好得


> Message: 6
> Date: Tue, 17 Oct 2006 11:36:34 +0800
> From: "ling" <xl-yc-lzj at necsoft.com.cn>
> Subject: [cpp] 关于返回内嵌类对象的成员函数
> To: "C++ Discuss Group" <cpp at codingnow.com>
> Message-ID: <001301c6f19d$7175c1a0$e40e1cac at xlyclzj>
> Content-Type: text/plain; format=flowed; charset="gb2312";
> 	reply-type=original
>
> 请教一个问题,下面代码中类Array2D的成员函数Array1D& operator[] (int index)
> 如果定义在类外面时(注释掉的代码),编译通不过,定义在类里面就没有问题,
> 不知道为什么。
> 编译错误:



More information about the Cpp mailing list