This is what my debugger says, but I can't find the problem.

Holding.h:15: warning: `class Holding' has virtual functions but non-virtual destructor
In file included from p6.cpp:12:
Recording.h:13: warning: `class Book::Recording' has virtual functions but non-virtual destructor
p6.cpp:90: error: expected `}' at end of input
Book.h:14: warning: `class Book' has virtual functions but non-virtual destructor
p6.cpp: In member function `int Book::main()':
p6.cpp:90: warning: no return statement in function returning non-void
p6.cpp: At global scope:
p6.cpp:90: error: expected unqualified-id at end of input
make: *** [p6.o] Error 1

#include <iostream>
#include <string>
#include "Holding.h"
#include "Book.h"
#include "Recording.h"


int main() {

    int C=0, D=1;
    int count=0, i=0;
    char selection, choice;
    string title, name, callnum;
    
    Holding *holding[5];
    
    cout<<"Enter holdings to be stored in a list:"<<endl <<endl;
    
    while(count != 5){
    	cout << "Enter B for book, R for recording: ";
	cin >> selection;
	
	switch(selection){
		case 'B':
			cout<<"Enter book title: ";
			cin >> title;
			cout<<"Enter book author: ";
			cin>> name;
			cout<<"Enter call number: ";
			cin >> callnum;
			
			Book *book = new Book(title, name, callnum);
			holding[count] = book;
			count++;
			break;
			
		case 'R':
			cout<<"Enter recording title: ";
			cin >> title;
			cout<<"Enter performer: ";
			cin>> name;
			cout<<"Enter format: (L)P, (C)assette, (R)eel_to_reel, (D)isk: ";
			cin >> choice;
			
			switch(choice){
				case 'C':
					cout<<"Enter call number: ";
					cin>>callnum;
					Recording *rec = new Recording(title, name, callnum, C);
					holding[count]=rec;
					count++;
					break;
				case 'D':
					cout<<"Enter call number: ";
					cin>>callnum;
					Recording *rec2 = new Recording(title, name, callnum, D);
					holding[count]=rec2;
					count++;
					break;
				//case 'L':
					//print LP;
					//break;
				//case 'R':
					//print Reel
					//break;
				default:
					cout<<"Error: Enter a valid selection"<<endl;
					break;
   			}//end inner switch
			break;
		default:
			cout<<"Error: Enter a valid selection"<<endl;
			break;
		}//end outter switch
	}//end while
	
	cout<<endl;
	cout<<"Here are the holdings: "<<endl <<endl;
	
    	for(i=0; i < 5; i++){
        	holding[i]->print();
    	}
}

Recommended Answers

All 5 Replies

You posted the wrong part of the program. The problem is with the two classes you have defined. Just declare the class destructor as virtual and the error will be fixed.

Holding.h:15: warning: `class Holding' has virtual functions but non-virtual destructor
In file included from p6.cpp:12:
Recording.h:13: warning: `class Book::Recording' has virtual functions but non-virtual destructor
p6.cpp:90: error: expected `}' at end of input
Book.h:14: warning: `class Book' has virtual functions but non-virtual destructor

The numbers that I have bolded are line numbers. Unfortunately, the way you posted your code there is no way of knowing which lines they refer to. I suggest you modify your post real quick to make the numbers meaningful.

Once you find the correct lines, the errors should be easy enough to fix, they're pretty elementary.

[edit]
AD covered your other issue. Fix the warnings about non-virtual destructors and the others may correct themselves.

Sorry, I didn't realized that I also cut off the header part. Here's the correct code with a synced error message.

In file included from p6.cpp:6:
Holding.h:10: warning: `class Holding' has virtual functions but non-virtual destructor
In file included from p6.cpp:8:
Recording.h:9: warning: `class Book::Recording' has virtual functions but non-virtual destructor
p6.cpp:85: error: expected `}' at end of input
Book.h:10: warning: `class Book' has virtual functions but non-virtual destructor
p6.cpp: In member function `int Book::main()':
p6.cpp:85: warning: no return statement in function returning non-void
p6.cpp: At global scope:
p6.cpp:85: error: expected unqualified-id at end of input
make: *** [p6.o] Error 1

/*  p6.cpp
*/    

#include <iostream>
#include <string>
#include "Holding.h"
#include "Book.h"
#include "Recording.h"

int main() {

    int C=0, D=1;
    int count=0, i=0;
    char selection, choice;
    string title, name, callnum;
    
    Holding *holding[5];
    
    cout<<"Enter holdings to be stored in a list:"<<endl <<endl;
    
    while(count != 5){
    	cout << "Enter B for book, R for recording: ";
	cin >> selection;
	
	switch(selection){
		case 'B':
			cout<<"Enter book title: ";
			cin >> title;
			cout<<"Enter book author: ";
			cin>> name;
			cout<<"Enter call number: ";
			cin >> callnum;
			
			Book *book = new Book(title, name, callnum);
			holding[count] = book;
			count++;
			break;
			
		case 'R':
			cout<<"Enter recording title: ";
			cin >> title;
			cout<<"Enter performer: ";
			cin>> name;
			cout<<"Enter format: (L)P, (C)assette, (R)eel_to_reel, (D)isk: ";
			cin >> choice;
			
			switch(choice){
				case 'C':
					cout<<"Enter call number: ";
					cin>>callnum;
					Recording *rec = new Recording(title, name, callnum, C);
					holding[count]=rec;
					count++;
					break;
				case 'D':
					cout<<"Enter call number: ";
					cin>>callnum;
					Recording *rec2 = new Recording(title, name, callnum, D);
					holding[count]=rec2;
					count++;
					break;
				//case 'L':
					//print LP;
					//break;
				//case 'R':
					//print Reel
					//break;
				default:
					cout<<"Error: Enter a valid selection"<<endl;
					break;
   			}//end inner switch
			break;
		default:
			cout<<"Error: Enter a valid selection"<<endl;
			break;
		}//end outter switch
	}//end while
	
	cout<<endl;
	cout<<"Here are the holdings: "<<endl <<endl;
	
    	for(i=0; i < 5; i++){
        	holding[i]->print();
    	}
}
/*  Holding.h
*/  

#ifndef HOLDING_H
#define HOLDING_H
#include <string>

using namespace std;

class Holding {
	//friend ostream &operator<<(ostream &out, const Holding &h) {
	//	out << "*** Information in Holding ***" << endl
        //    << "Name:  " << h.name << endl
        //    << "Title:  " << h.title << endl
        //    << "Call Number:  " << h.callnum << endl; 
       // return out;
    //}
    
    
    public:
        Holding(string t, string a, string c) {
        
            title = t;
	    name = a; //author or performer
	    callnum = c; //call number
        }
        
        Holding() {}
        
    
        void setTitle(string s) {
            title = s;
        }
        
        string getTitle() {
            return title;
        }
        
        void setName(string s) {
            name = s;
        }
        
        string getName() {
            return name;
        }
        
        void setCallNum(string s) {
            callnum = s;
        }
        
        string getCallNum() {
            return callnum;
        }
        
        virtual void print() {
        cout << "*** Information in Holding ***" << endl
            << "Name:  " << name << endl
            << "Title:  " << title << endl
            << "Call Number:  " << callnum << endl; 
    }           
        
    protected:
        string title, name, callnum;
};    
#endif
/*  Book.h
*/  

#ifndef BOOK_H
#define BOOK_H
#include <string>

using namespace std;

class Book : public Holding {
 	//friend ostream &operator<<(ostream &out, const Book &b) {
       // out << "** Information on Book ** " << endl
        //    <<"BOOK: "<< b.name <<" \""< b.<title<<"\" "<< b.callnum <<endl;
       // return out;
  //  }   

    
    public:
        Book(string t, string a, string c):
		Holding(t,a,c){}

        virtual void print() {
            		cout <<"BOOK: "<< name <<" \""<<title<<"\" "<< callnum <<endl;
};
#endif
/*  Recording.h
*/  

#ifndef RECORDING_H
#define RECORDING_H

//using namespace std;

class Recording : public Holding {
    //friend ostream &operator<<(ostream &out, const Recording &r) {
    //    out << "** Information on Recording ** " << endl
    //        <<"RECORDING: \"" << r.title <<"\" "<< r.name<<" (Cassette) "r.callnum <<endl;
    //    return out;
    //}  

    
    public:
        Recording(string t, string a, string c, int n):
		Holding(t,a,c){
			num= n;
			}
       
        void setNum(float f) {
            num = f;
        }
        
        float getNum() {
            return num;
        }
	
        virtual void print() {
                if(num ==0){
            		cout <<"RECORDING: \"" << title <<"\" "<< name<<" (Cassette) "<<callnum <<endl;
			}
        	else{
            		cout <<"RECORDING: \"" << title <<"\" "<< name<<" (CD) "<<callnum <<endl;           
        	}
	}

        
    protected:
        float num;
};
#endif

The error is that you haven't defined any default constructors or any destructors. It is not a direct syntax issue, you can't just read through the code and see it.

Like AD said previously, and the warnings you received indicate, you need to properly declare and define/implement your destructors. Make sure you declare them as virtual.

class exBase {
  int anIntMem;
public:
  exBase(): anIntMem(0) {} //default constructor
  virtual ~exBase() {} //virtual destructor
};
class exDerived : public exBase{
  double aDblMem;
public:
  exDerived(): aDblMem(0.0) {} //default constructor
  virtual ~exDerived() {} //virtual destructor
};

Have a look at this for more info.

The print() method in the Book.h is lacking a '}'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.