简体   繁体   English

C ++继承/ #include(多个编译器错误)

[英]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. 但是,我有很多(192个还在计数中……)编译器错误。

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 -复制-复制处理程序-图书-图书处理程序-目录-目录处理程序-成员-成员处理程序-MembershipApplications -MembershipApplicationsHandler-发票-发票处理程序-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. 复制是我使用继承的第一类,而OrdersHandler是我使用继承的最后一类,包括将它们链接在一起。

At the start of "Copy.h" I have typed this: 在“ Copy.h”的开头,我输入了以下内容:

#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: 在“ CopyHandler.h”的开头,我输入了以下内容:

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

public Book //inheritance from book

At the start of "Book.h" I have typed this: 在“ Book.h”的开头,我输入了以下内容:

#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... 但是,这仍然会导致我产生3位数字的错误...

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? CopyHandler应该从Copy继承,是吗? If so, the syntax is: 如果是这样,则语法为:

class CopyHandler : public Copy

Your errors stem from: 您的错误源于:

Copy inherits from CopyHandler but Copy does not know that. CopyCopyHandler继承,但是Copy不知道。 CopyHandler has not been declared yet. CopyHandler尚未被声明。

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 好的语法教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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