Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: ISO C++ forbids declaration of ‘type name’ with no type

Tags:

c++

I have a nested class definition and get errors on applying a cast to the pointer to it. The following program compiles with the error:

test.cpp: In member function ‘void* Achild<T>::test(void*)’:
test.cpp:24:31: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
       ShortName::ptr = (const ShortName::Ptr*)input;
                               ^~~~~~~~~
test.cpp:24:25: error: expected primary-expression before ‘const’
       ShortName::ptr = (const ShortName::Ptr*)input;
                         ^~~~~
test.cpp:24:25: error: expected ‘)’ before ‘const’
       ShortName::ptr = (const ShortName::Ptr*)input;
                        ~^~~~~
                         )
test.cpp:25:6: warning: no return statement in function returning non-void [-Wreturn-type]
      }

I can't understand why i am getting errors on line 24. Any help would be appreciated!

template<typename T>
   class VeryLongName
   {
     public:
         class Ptr
         {
                 public:
                         int a;
                         Ptr() = default;
         };
         const Ptr* ptr;

   };

   template <typename T>
   class Achild: public VeryLongName<T>
   {
     using ShortName = VeryLongName<T>;
   public:
     Achild<T>() = default;

     void test(void * input)
     {
             ShortName::ptr = (const ShortName::Ptr*)input;
     }

   };

int main()
{
        auto *achild = new Achild<int>();
        auto a = new VeryLongName<int>::Ptr();
        achild->test((void*)a);
}
like image 298
Captain Jack sparrow Avatar asked Oct 24 '25 14:10

Captain Jack sparrow


1 Answers

You are missing a typename declaration:

ShortName::ptr = (const typename ShortName::Ptr*) input;

as ShortName depends on your template type.

like image 85
Thomas Caissard Avatar answered Oct 26 '25 04:10

Thomas Caissard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!