在c ++中创建类型类数组时遇到问题

时间:2018-04-16 17:33:48

标签: c++

我正在尝试为大学作业制作一个简单的程序,可以在程序中添加和查看书籍。

我的数组出现错误,例如:未知覆盖说明符,语法错误:缺少','前'',语法错误:缺失')'之前';',意外标记在';'之前。任何帮助将不胜感激

//Header.h

class Eason {
    int b=0;
    book array[100];
protected:
    std::string title;
    std::string publisher;
    int numInStock;
public:
    void addBook(std::string, std::string, int, std::string, std::string);
    void search(std::string);

};

class book:public Eason {
    std::string author;
    int edition;
    std::string barcode;
public:
    book();
    ~book();
    void setValues(std::string, std::string,int,  std::string, std::string);
    void printValues();
};

//class.cpp

#include "stdafx.h"
#include <iostream>
using namespace std;

void Eason::addBook(string author, string title, int edition, string 
publisher, string barcode)
{ 
    array[b].setValues(author, title, edition, publisher, barcode);
}
void Eason::search(string title)
{
    for (int i = 0; i < 100; i++)
    {
        if (array[i].title == title)
        {
            array[i].printValues();
            break;
        }
        if (array[i].title.length==0)
        {
            cout << "Book not found" << endl;
        }
    }
}

book::book()
{

}
book::~book()
{

}
void book::setValues(string author, string title, int edition, string 
publisher, string barcode)
{
    author = author;
    title = title;
    edition = edition;
    publisher = publisher;
    barcode = barcode;
}
void book::printValues()
{
    cout << "Title: " << title << "\nAuthor: " << author << endl;

}

//stdafx.h
#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include "Header.h"

//main

0 个答案:

没有答案