Thread: Basic Inheritence Question

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    45

    Basic Inheritence Question

    I am having trouble making a structure where Queue is a child of QueueItem, I get a "expected class name" error.
    I'm doing this in xCode.

    I have 4 files:
    Queue.cpp, Queue.h, QueueItem.cpp,QueueItem.h

    For QueueItem.cpp I have:
    Code:
    #include "QueueItem.h"
    
    
    class QueueItem
    {
    public:
        virtual void print() = 0;
    };
    QueueItem.h
    Code:
    #ifndef __Practice__QueueItem__
    #define __Practice__QueueItem__
    
    
    #include <stdio.h>
    
    
    #endif
    Queue.cpp
    Code:
    #include "Queue.h"
    
    
    class Queue : public QueueItem // I get "expected class" error here
    {  
       void print();
    };
    and Queue.h
    Code:
    #ifndef __Practice__Queue__
    #define __Practice__Queue__
    
    #include <stdio.h>
    #include "QueueItem.h"
    #endif
    So I get an error at "class Queue : public QueueItem", but I have included the QueueItem.h header in the Queue header so I don't get why it says it's expecting a class.
    I also tried putting the include QueueItem directly into the Queue c++ code and that didn't work.

  2. #2
    Registered User
    Join Date
    Jan 2016
    Posts
    45
    Nvm i figured it out.
    "Class" should go in the header file and the not cpp file.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Err... why is Queue derived from QueueItem? Shouldn't a Queue object contain QueueItem objects?
    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. Inheritence
    By Lesshardtofind in forum C# Programming
    Replies: 10
    Last Post: 12-02-2012, 05:06 AM
  2. Help with Inheritence
    By sprankles in forum C++ Programming
    Replies: 2
    Last Post: 04-23-2011, 01:01 PM
  3. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  4. Question about Inheritence
    By chadmandoo in forum C++ Programming
    Replies: 22
    Last Post: 11-30-2008, 12:50 PM
  5. Inheritence Question
    By kas2002 in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2006, 08:32 AM

Tags for this Thread