Intellisense Reports Error but Code Still Compiles (VS 2017) (C++)

Viewed 205

I'm having an issue where Visual Studio 2017's Intellisense is reporting an error message, but the code itself still compiles and runs as expected (I think). As a result, I'm not sure if I'm doing this the wrong way and setting myself up for failure when I start to do more complicated things or if it's simply an Intellisense bug.

The most simplified version of the code that I could produce that results in this error is as follows:

template <typename T>
class A
{
  protected:
  template <typename T>
  class A1
  {
    protected:
    typename T::container ct; // should be inherited by B1
    A1(typename T::container& j) : ct(j) {}
  };
  public:
  A() {}
};

class B : public A<B>
{
  public:
  struct container
  {
    int data;
    container(const int x) : data(x) {}
  };
  B() {}
  private:
  class B1 : public A1<B>
  {
    B1(container& i) : A<B>::A1<B>(i) {} // error appears here
  };
};

The error message that I'm receiving is:

"no instance of constructor "A::A1::A1 [with T=B, T=B]" matches the argument list. Argument types are: (B::container)"

The exact position of the red squiggle can be seen here: https://prnt.sc/fyd258

The reason I have these classes set up this way is because, in my actual code, I'm using templates and inheritance in combination to create generic methods in the base class which can call methods in the inherited class. Furthermore, I'm needing it designed this way so that the struct defined in the derived class can be made a member variable of the nested classes in the derived class (B1) automatically by the nested class in the base class that it inherits from (A1).

I just don't understand why Intellisense is giving me the error when the code itself still compiles. Maybe I just need to change something slightly, or maybe I need to completely rethink my design (I'm assuming the latter). What do you think?

0 Answers
Related