简体   繁体   中英

C++ Inheritance / #include (Multiple compiler errors)

this is my first post, and I'm only a first year programming student. So please excuse any amateur/novice language or poor understanding from me, cheers =)

For my Application Modelling assignment, I've been given the task of creating a library system, using object oriented programming. I have currently set up the classes for this, with all the methods (gets, sets etc) and I have absolutely no syntax errors .

However, I have a multitude (192 and counting...) of compiler errors.

I have a feeling this is because of how I have used inheritance .

I have used the following classes (both with source and header files):

-Copy -Copy Handler -Book -Book Handler -Catalog -Catalog Handler -Member -Member Handler -MembershipApplications -MembershipApplicationsHandler -Invoice -Invoice Handler -Order -OrderHandler -Orders -OrdersHandler

(The handler classes are simply used to create their corresponding object, eg copy handler creates and returns a copy object.)

Copy being the first class and OrdersHandler being the final class I have used inheritance and includes to link them all together.

At the start of "Copy.h" I have typed this:

#pragma once
#include <array>   //for array used later on
#include <vector>  //for std::vector
#include <string>  //for std::string
using namespace std;

class Copy:
    public CopyHandler //Inheriting from copy handler class

At the start of "CopyHandler.h" I have typed this:

#pragma once
#include "Copy.h"
class CopyHandler:

public Book //inheritance from book

At the start of "Book.h" I have typed this:

#pragma once
#include "CopyHandler.h"
using namespace std;
class Book:
    public BookHandler

So essentially, in each header file I include the previous file and "public" the next file. However, this still causes me 3 digits worth of errors...

Any help would be greatly appreciated.

Cheers =)

(The handler classes are simply used to create their corresponding object, eg copy handler creates and returns a copy object.)

That being said, I think you have your understanding inheritance syntax flipped. CopyHandler should inherit from Copy , yes? If so, the syntax is:

class CopyHandler : public Copy

Your errors stem from:

Copy inherits from CopyHandler but Copy does not know that. CopyHandler has not been declared yet.

Inheritance is done by the child class(initiated by the child class) not by the parent class forcing inheritance down, as your syntax would suggest.

Good syntax tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM