2013-05-30 44 views
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和快递)告诉“CSR没有成员operator []的”

+1

你能指出编译器抱怨的行号吗?另外,什么是'SVDFeatureCSR'? – arne

+0

@arne我声明朋友功能的行。我已经简单地将SVDFeatureCSR更改为CSR – zoujyjs

回答

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); 
    }; 
}; 
0

你需要一个你的内部类的前向声明 - 但不幸的是,这是不允许的。
This post有一些可能的解决办法 - 没有特别吸引人的。

相关问题