0

I have a class manage the content of a file and convert the file to a binary buffer, and I have a inner class which is a element in the file(basically it represents a single line). Like:

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

The compiler(VS 2012 Express) tells that "CSR has no member operator[]"

Joey.Z
  • 4,492
  • 4
  • 38
  • 63
  • 1
    Can you please indicate the line number the compiler complains about? Also, what is `SVDFeatureCSR`? – arne May 30 '13 at 08:34
  • @arne the line that I declare the friend function. And I have changed the SVDFeatureCSR to CSR for simplisity – Joey.Z May 30 '13 at 09:57

2 Answers2

0

I'm not sure what the language rule is, but forward declaring Elem seems to make both gcc 4.7 and VS 2010 happy:

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 );
    };
};
Pablo
  • 8,644
  • 2
  • 39
  • 29
0

You need a forward declaration of your inner class - but unfotunately that is not allowed.
This post has some possible work arounds - none particularly attractive.

Community
  • 1
  • 1
Ricibob
  • 7,505
  • 5
  • 46
  • 65