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

147,842

Solution 1

You forgot the return types in your member function definitions:

int ttTree::ttTreeInsert(int value) { ... }
^^^               

and so on.

Solution 2

Your declaration is int ttTreeInsert(int value);

However, your definition/implementation is

ttTree::ttTreeInsert(int value)
{
}

Notice that the return type int is missing in the implementation. Instead it should be

int ttTree::ttTreeInsert(int value)
{
    return 1; // or some valid int
}
Share:
147,842

Related videos on Youtube

user2264035
Author by

user2264035

Updated on June 10, 2020

Comments

  • user2264035
    user2264035 almost 4 years

    I'm getting the following errors:

    ISO C++ forbids declaration of ttTreeInsert with no type

    ISO C++ forbids declaration of ttTreeDelete with no type

    ISO C++ forbids declaration of ttTreePrint with no type

    prototype for int ttTree::ttTreePrint() does not match any in class ttTree

    candidate is: void ttTree::ttTreePrint()

    Here is my header file:

    #ifndef ttTree_h
    #define ttTree_h
    
    class ttTree 
    {
    public:
      ttTree(void);
      int ttTreeInsert(int value);
      int ttTreeDelete(int value);
      void ttTreePrint(void);
      
    };
    
    #endif
    

    Here is my .cpp file:

    #include "ttTree.h"
    
    ttTree::ttTree(void)
    {
      
    }
    
    ttTree::ttTreeInsert(int value)
    {
    }
    
    ttTree::ttTreeDelete(int value)
    {
    }
    
    ttTree::ttTreePrint(void)
    {
    }
    

    Can anyone point out what is causing these errors? Thank you!

    • Chandra Shekhar
      Chandra Shekhar over 3 years
      Earlier version of c++ treated the non return type function as void. But ISO C++ forbids declaration with no type to avoid the unexpected behavior of the programs and function .Here a quick fix would be to mention the appropriate return type of the functions that you are declaring .