0

我有一个类管理文件的内容并将文件转换为二进制缓冲区,我有一个内部类,它是文件中的一个元素(基本上它代表一行)。喜欢:

class CSR{
private:
    //some fields
public:
    Elem operator[](int numRow);
    //other methods
public:
    class Elem{
        private:
            //other fields
        public:
            friend CSR::Elem CSR::operator[]( int r );
    };
};

编译器(VS 2012 Express)告诉“CSR 没有成员运算符 []”

4

2 回答 2

0

我不确定语言规则是什么,但向前声明 Elem 似乎让 gcc 4.7 和 VS 2010 都高兴:

class CSR{
private:
    //some fields
public:
    class Elem;
    Elem operator[](int numRow);
    //other methods
public:
    class Elem{
        private:
            //other fields
        public:
            friend CSR::Elem CSR::operator[]( int r );
    };
};
于 2013-05-30T08:49:27.153 回答
0

您需要对您的内部类进行前向声明 - 但不幸的是,这是不允许的。
这篇文章有一些可能的解决方法——没有一个特别有吸引力。

于 2013-05-30T08:54:29.780 回答