0

The following code fails to compile in Visual studio 2103 Express preview:

template<int N> class TTOuter;

template<>
class TTOuter<1>
{
public:
    class inner
    {
        friend class TTOuter<1>;

    private:
        inner(int n) : data(n) {;}
        int data;
    };

private:
    inner x;

public:
    TTOuter(int n) : x(n) {;} //Fails here
};

Error: "TTOuter<1>::inner::inner(int n)" is inaccessible

An analogous access succeeds if the outer class is not a specialized template:

class Outer
{
public:
    class inner
    {
        friend class Outer;

    private:
        inner(int n) : data(n) { ; }
        int data;
    };

private:
    inner x;

public:
    Outer(int n) : x(n) { ; }
};

Gives no error.

I tried forward declaring TTOuter<1> like:

template<> class TTOuter<1>;

I also tried replacing the friend declaration by:

template<int N> friend class TTOuter;

But neither works.

Would appreciate any insight. Thank You.

skm
  • 329
  • 2
  • 9
  • It compiles fine with VS2012: http://rise4fun.com/Vcpp/3R . Please show a code that _does_ cause the error. – gx_ Aug 28 '13 at 16:31

1 Answers1

1

I think it is nothing more than a typo in your code

public:
    TOuter(int n) : x(n) {;} //Fails here
  //^^^^^^ Shouldn't it be TTouter???
};

Edited:

If I edit a bit your code:

class TTOuter<1>
{
public:
    typedef TTOuter this_type; // <-- I add this typedef
    class inner
    {
        friend class this_type; // <-- Intellisense works
        //friend class TTOuter<1>; // <-- intellisense barks
        inner(int n) : data(n) { ; }
        int data;
    };
    TTOuter(int n) : x(0) {}
};

Now intellisense stops complaining.

Jason
  • 409
  • 2
  • 7
  • I see in your code you have edited the constructor and replaced TOuter with TTOuter. That compiles fine in VS2013 preview – Jason Aug 28 '13 at 16:24
  • The code in my editor has TTOuter. Had just copied it wrongly. I'm pasting the code exactly as in the editor, but oddly, in my case, it is not getting past intellisense. – skm Aug 28 '13 at 16:29
  • 1
    @skm It compiles just fine. Intellisense has nothing to do with the compiler. – catscradle Aug 28 '13 at 16:31
  • 1
    I see. Looks like a bug in intellisense. – Jason Aug 28 '13 at 16:35
  • 1
    Oh, I see. I tried compiling a test.cpp woth TTOuter<1> X(5), and there is no problem. Thanks. – skm Aug 28 '13 at 16:38
  • Thanks to both of you. BTW and off-topic, do you happen to know when the final version of VS 2013 is due? – skm Aug 28 '13 at 16:40
  • Interesting - meaning I have no clue. I didn't even know that "typedef TTOuter this_type" could be a valid typedef. Oddly enough, if I replace it with "typedef TTOuter<1> this_type" the errors still remain. Certainly looks like a bug in intellisense. – skm Aug 28 '13 at 17:13
  • @Juan, Thanks for your experiment. The VS 2013 can be misleading, since even a minor syntax error in the code will make it output all the (possibly unrelated and possibly _wrong_) intellisense errors. – skm Aug 28 '13 at 17:31