Hi there.
I am currently trying to get my head around using classes across two files. I currently have a super class and a sub class stored in a file and the main function in another. When I try and pass arguments to the class they work fine if the values are int's. However, what I want to pass are book names. Here is the code.
//publication.cpp
#include <iostream>
#include <string>
using namespace std;
//the publication super class
class publication
{
private:
char title; //the title of the book
char genre; //the genre of the book
double date; //the date of release
public:
//construct publication
publication(char t, char g, double d)
{
title = t;
genre = g;
date = d;
}
//accessor functions
char get_title() { return title; }
char get_genre() { return genre; }
double get_date() { return date; }
};
//the book sub class
class book : public publication
{
private:
int pages; //the number of pages
public:
//construct book
book (char t, char g,
double d, int p) : publication (t ,g, d)
{
pages = p;
}
//accessor funtions
int get_pages() { return pages; }
};
and the other file:
//main.cpp
#include <iostream>
#include <string>
#include "publication.cpp"
using namespace std;
int main()
{
//write a book!
book dune(dune, scifi, 1965, 1021);
return 0;
}
I tried using type string instead of char but that didn't work either. I know I won't get any printed content, but I am working through it in baby steps.
Compiler errors are:
error C2065: 'dune' : undeclared identifier
error C2065: 'scifi' : undeclared identifier
Please can I have some help?
Thank you.