Thread: fpermissive compilation error using inheritance

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    22

    fpermissive compilation error using inheritance

    I'm new to C++... I have list.h file containing functions for linked lists, and then I have a queue.h that uses inheritance to use functions from the list.h... The errror below occurs while compiling. I don't understand, I've been trying to understand the error but somehow I'm lost. What must I do?

    Sample error output below...

    There are no arguments to 'isEmpty' that depend on a template parameter, so a declaration of 'isEmpty' must be available [-f permissive] return isEmpty();

    removeFromFront' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] return removeFromFront( data );

    'insertAtBack' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] insertAtBack( data );

    there are no arguments to 'print' that depend on a template parameter, so a declaration of 'print' must be available [-fpermissive]
    print();




    My List.h is as follows:

    Code:
     
    #ifndef LIST_H
    #define LIST_H
    
    
    #include <iostream>
    #include <assert.h>
    #include "listnd.h"
    using std::cout;
    using std::cin;
    using std::endl;
    
    
    template< class NODETYPE >
    class List {
    public:
       List();                            
       List( const List< NODETYPE > & );  
       ~List();                           
       void insertAtFront( const NODETYPE & );
       void insertAtBack( const NODETYPE & );
       NODETYPE removeFromFront( NODETYPE & );
       NODETYPE displayTheFront( NODETYPE &value );
       bool removeFromBack( NODETYPE & );
       bool isEmpty() const;
       void print() const;
    private:
       ListNode< NODETYPE > *firstPtr;  // pointer to first node
       ListNode< NODETYPE > *lastPtr;   // pointer to last node
    
    
       // Utility function to allocate a new node
       ListNode< NODETYPE > *getNewNode( const NODETYPE & );
    };
    
    
    // Default constructor
    template< class NODETYPE >
    List< NODETYPE >::List() { firstPtr = lastPtr = 0; }
    
    
    // Copy constructor
    template< class NODETYPE >
    List< NODETYPE >::List( const List<NODETYPE> &copy )
    {
       firstPtr = lastPtr = 0;  // initialize pointers
    
    
       ListNode< NODETYPE > *currentPtr = copy.firstPtr;
    
    
       while ( currentPtr != 0 ) {
          insertAtBack( currentPtr -> data );
          currentPtr = currentPtr -> nextPtr;
       }
    }
    
    
    // Destructor 
    
    
    template< class NODETYPE >
    List< NODETYPE >::~List()
    {
       if ( !isEmpty() ) {    // List is not empty
          cout << "Destroying nodes ...\n";
    
    
          ListNode< NODETYPE > *currentPtr = firstPtr, *tempPtr;
    
    
          while ( currentPtr != 0 ) {  // delete remaining nodes
             tempPtr = currentPtr;
             cout << tempPtr -> data << ' ';
             currentPtr = currentPtr -> nextPtr;
             delete tempPtr;
          }
       }
    
    
       cout << "\nAll nodes destroyed\n\n";
    }
    
    
    // Insert a node at the front of the list
    template< class NODETYPE >
    void List< NODETYPE >::insertAtFront( const NODETYPE &value )
    {
       ListNode<NODETYPE> *newPtr = getNewNode( value );
    
    
       if ( isEmpty() )  // List is empty
          firstPtr = lastPtr = newPtr;
       else {          // List is not empty
          newPtr -> nextPtr = firstPtr;
          firstPtr = newPtr;
       }
    }
    
    
    // Insert a node at the back of the list
    template< class NODETYPE >
    void List< NODETYPE >::insertAtBack( const NODETYPE &value )
    {
       ListNode< NODETYPE > *newPtr = getNewNode( value );
    
    
       if ( isEmpty() )  // List is empty
          firstPtr = lastPtr = newPtr;
       else {          // List is not empty
          lastPtr -> nextPtr = newPtr;
          lastPtr = newPtr;
       }
    }
    
    
    // Delete a node from the front of the list
    template< class NODETYPE >
    NODETYPE List< NODETYPE >::removeFromFront( NODETYPE &value )
    {
       if ( isEmpty() )             // List is empty
          return false;             // delete unsuccessful
       else {
          ListNode< NODETYPE > *tempPtr = firstPtr;
    
    
          if ( firstPtr == lastPtr )
             firstPtr = lastPtr = 0;
          else
             firstPtr = firstPtr -> nextPtr;
    
    
          value = tempPtr -> data;  // data being removed
          delete tempPtr;
          return value;              // delete successful
       }
    }
    
    
    template< class NODETYPE >
    NODETYPE List< NODETYPE >::displayTheFront( NODETYPE &value )
    {
    	if ( isEmpty() ){             
          cout<<"Ok\n\n";
    	  menu ();
    	}
       else {
          ListNode< NODETYPE > *tempPtr = firstPtr;
    
    
          if ( firstPtr == lastPtr )
             firstPtr = lastPtr = 0;
          else
             firstPtr = firstPtr -> nextPtr;
    
    
          value = tempPtr -> data;  
          
          return value;              
       }
    }
    
    
    // Delete a node from the back of the list
    template< class NODETYPE >
    bool List< NODETYPE >::removeFromBack( NODETYPE &value )
    {
       if ( isEmpty() )
          return false;   // delete unsuccessful
       else {
          ListNode< NODETYPE > *tempPtr = lastPtr;
    
    
          if ( firstPtr == lastPtr )
             firstPtr = lastPtr = 0;
          else {
             ListNode< NODETYPE > *currentPtr = firstPtr;
    
    
             while ( currentPtr -> nextPtr != lastPtr )
                currentPtr = currentPtr -> nextPtr;
    
    
             lastPtr = currentPtr;
             currentPtr -> nextPtr = 0;
          }
    
    
          value = tempPtr -> data;
          delete tempPtr;
          return true;   // delete successful
       }
    }
    
    
    // Is the List empty?
    template< class NODETYPE >
    bool List< NODETYPE >::isEmpty() const { return firstPtr == 0; }
    
    
    // Return a pointer to a newly allocated node
    template< class NODETYPE >
    ListNode< NODETYPE > *List< NODETYPE >::getNewNode( const NODETYPE &value )
    {
       ListNode< NODETYPE > *ptr = new ListNode< NODETYPE >( value );
       assert( ptr != 0 );
       return ptr;
    }
    
    
    // Display the contents of the List
    template< class NODETYPE >
    void List< NODETYPE >::print() const
    {
       if ( isEmpty() ) {
          cout << "The list is empty\n\n";
          return;
       }
    
    
       ListNode< NODETYPE > *currentPtr = firstPtr;
    
    
       cout << "The list is: ";
    
    
       while ( currentPtr != 0 ) {
          cout << currentPtr -> data << ' ';
          currentPtr = currentPtr -> nextPtr;
       }
    
    
       cout << "\n\n";
    }
    
    
    
    
    
    
    #endif

    My queue.h is as follows:

    Code:
    #ifndef QUEUE_H
       #define QUEUE_H
     
       #include "List.h" // List class definition
     
       template< typename QUEUETYPE >
       class Queue : private List< QUEUETYPE >
      {
      public:
         // enqueue calls List member function insertAtBack
         void enqueue( const QUEUETYPE &data )
         {
            insertAtBack( data );
         } // end function enqueue
    
    
         // dequeue calls List member function removeFromFront
         bool dequeue( QUEUETYPE &data )
         {
            return removeFromFront( data );
         } // end function dequeue
    
    
         // isQueueEmpty calls List member function isEmpty
         bool isQueueEmpty() const
         {
            return isEmpty();
         } // end function isQueueEmpty
    
    
         // printQueue calls List member function print
         void printQueue() const
         {
            print();
         } // end function printQueue
      }; // end class Queue
    
    
      #endif
    Last edited by ubmattpangolin; 10-18-2015 at 12:15 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you post your code again: copy and paste your code as plain text, as-is (no markup, whether HTML or embedded bbcode). When you post your code within [code][/code bbcode tags, the forum software will add line numbers and syntax highlighting for you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    22
    Hi laserlight, I belive I fixed the formatting

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ubmattpangolin
    There are no arguments to 'isEmpty' that depend on a template parameter, so a declaration of 'isEmpty' must be available [-f permissive] return isEmpty();
    Since the compiler is confused about the isEmpty call, I suggest that you be explicit that it is from the base class template:
    Code:
    return List< QUEUETYPE >::isEmpty();
    The same likely applies for the others. That said, I would have preferred to use a member variable instead of private inheritance.

    By the way, using directives and using declarations should not appear at namespace scope in a header file, so I would either remove these:
    Code:
    using std::cout;
    using std::cin;
    using std::endl;
    and fully qualify the names within the functions, or move these using declarations to the functions that use these names.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2015
    Posts
    22
    Hi Laserlight, I appreciate it a lot!!! Using what you said got rid of all the errors Maybe you're a bit busy, but I'll still ask. Could you explain to me or break it down in small understanding pieces of what is it that was happening? Would appreciate it, would like to fully understand what was the error. I got this from a Deitel learn to program C++, it's a bit outdated but it was the exact code, could this be old coding conventions?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ubmattpangolin
    Could you explain to me or break it down in small understanding pieces of what is it that was happening? Would appreciate it, would like to fully understand what was the error. I got this from a Deitel learn to program C++, it's a bit outdated but it was the exact code, could this be old coding conventions?
    You could read the answer to this FAQ: Why am I getting errors when my template-derived-class uses a member it inherits from its template-base-class?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid conversion from 'int*' to 'int' [-fpermissive]
    By telmo_d in forum C Programming
    Replies: 2
    Last Post: 06-02-2015, 08:47 AM
  2. Replies: 5
    Last Post: 08-31-2013, 07:59 PM
  3. Compilation Error
    By samuraiexx in forum C Programming
    Replies: 4
    Last Post: 09-21-2011, 12:19 AM
  4. Error during compilation.
    By arupsarkar in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2010, 11:26 PM
  5. error: was not declared in this scope compilation error
    By i_r_tomash in forum C Programming
    Replies: 2
    Last Post: 05-27-2010, 07:44 AM