Inheritance

This is a discussion on Inheritance within the C++ Programming forums, part of the General Programming Boards category; what the hell? i didnt do anything wrong lol. so far as i can see... linkedList.h Code: class linkedList:public linkedQueue ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    Inheritance

    what the hell? i didnt do anything wrong lol. so far as i can see...

    linkedList.h
    Code:
    class linkedList:public linkedQueue
    {
          public:
                 linkedList();
                 ~linkedList();
          
          private:
    
    };
    linkedQueue.h
    Code:
    struct Node 
    {
           int elem;
           Node *next; 
    };
    
    class linkedQueue
    {  
          typedef int el_t;
             
          public:
                 linkedQueue();
                 ~linkedQueue();
                 
                 void addRear(el_t newNum);
                 void deleteFront();
                 
                 bool isEmpty();
                 int getSize();
                 void displayAll();
                 
          private:
                  int count;
                  Node *front,*rear,*temp;//front and rear used to show the front
                                          //and the rear of the queue respectivley.
                                          //temp is used for deleteing elements
                  void queueError(char* mesg);
    };
    it keeps saying 'expected class-name before '{' token'

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you including linkedQueue.h in your linkedList.h?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    ya i tried including it and not including it. this is what i have for the whole files...

    linkedList.h
    Code:
    #ifndef linkedList_H
    #define linkedList_H
    
    #include<iostream>
    #include "linkedQueue.h"
    
    using namespace std;
    
    class linkedList:public linkedQueue
    {
          public:
                 linkedList();
                 ~linkedList();
                 
                 void addFront(el_t newNum);
                 void deleteRear(el_t& oldNum);
                 int search(el_t& key);
                 void deleteIth(int I,el_t& oldNum);
          
          private:
    
    };
    
    #endif //linkedList_H
    linkedQueue.h
    Code:
    #ifndef linkedQueue_H
    #define linkedQueue_H
    
    #include<iostream>
    
    using namespace std;
    
    struct Node 
    {
           int elem;
           Node *next; 
    };
    
    class linkedQueue
    {  
          typedef int el_t;
             
          public:
                 linkedQueue();
                 ~linkedQueue();
                 
                 void addRear(el_t newNum);
                 void deleteFront();
                 
                 bool isEmpty();
                 int getSize();
                 void displayAll();
                 
          private:
                  int count;
                  Node *front,*rear,*temp;//front and rear used to show the front
                                          //and the rear of the queue respectivley.
                                          //temp is used for deleteing elements
                  void queueError(char* mesg);
    };
    
    
    #endif

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure what's wrong, but don't use "using namespace std" in a header-file - that wil screw up the entire system of "namespaces".

    Oh, and don't put "Node *temp; // used for deleting" inside your class - it just occupies extra space, and since it's just a temporary that isn't needed for to be kept around, it's doesn't belong in the class - it belongs in the delete member function.

    Can you post the exact error message with line numbers, please.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    ooo, good advice about the temp thanks. i think i got it now, seemed to be something with my ide. it was telling me that i had invalid classes and they couldnt be found even though they were there, i messed around witht the project settings and seemed to have gotten it. btw which ide would you reccommend? im using dev C++ at the moment.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm a bit old-fashioned, so I often use Emacs and gcc on standalone - but Visual Studio Express is a slick environment with very good integration of all necessary tools - Windows only, of course.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    ya ive still to try and use visual studio. well thanks a lot for all your advice, it really helped me out.

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You should also make your destructors virtual, otherwise the wrong destructor might get called and leak resources.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 08:04 AM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  4. Inheritance and Polymorphism
    By bench386 in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2004, 09:19 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21