Base class and derived class constructors

Hey guys
I got these 2 errors in my code after implementing the derived class's constructor:
Error 1 error C2512: 'Show' : no appropriate default constructor available c:\users\hebrew\documents\visual studio 2010\projects\targeel3\targeel3\concert.cpp 4

2 IntelliSense: no default constructor exists for class "Show" c:\users\hebrew\documents\visual studio 2010\projects\targeel3\targeel3\concert.cpp 4



Base class's header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  #pragma once
#ifndef _SHOW_H
#define _SHOW_H

#include <string>
#include<iostream>
#include<list>

using namespace std;

class Show
{
private:
	string ShowName;
	int ShowYear,ShowDay,ShowMonth;
	int cost;
	int sold;
	list<Show> performers;

public:
	Show(int day,int month, int year);
	~Show(void);
	void SetPerformers();
	void setSold();
	

};

#endif //_SHOW_H 


Base Class's cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Show::Show(int day,int month, int year) {
	ShowYear=year;
	ShowDay=day;
	ShowMonth=month;
}



Show::~Show(void) //I will  mplement later
{
}

void Show::SetPerformers() { //I will implement this later
	return;

}

void Show::setSold() {
	sold--;
}


Derived Class's header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#ifndef _CONCERT_H
#define _CONCERT_H

#include <string>
#include <list>
#include <string>
#include<iostream>
using namespace std;

#include "show.h"
class Concert : public Show
{
private:
	string conductor;
	list<Concert> instruments;
	list<Show> musicians;
public:
	Concert(string conName);
	~Concert(void);
	
};

#endif //_CONCERT_H 


Derived Class's cpp:
1
2
3
4
5
6
7
8
9
10
11
#include "Concert.h"


Concert::Concert(string conName) {
	conductor=conName;
}


Concert::~Concert(void)
{
}


Can anyone help me and tell me what should i add to the derived class's constructor in order for this code to compile?
Thank you in advance:)
I implemented the destructors:
1
2
3
4
5
6
Concert::~Concert(void)
{
	instruments.erase(instruments.begin(),instruments.end());
	musicians.erase(musicians.begin(),musicians.end());
}


and in the base class's cpp:
1
2
3
4
Show::~Show(void)
{
	performers.erase(performers.begin(),performers.end());
}



I still get the two errors though.
Read the error message more closely.
no default constructor

The issue is not the desctructor. list<> will clean itself up.

Concert derives from Show. Concert's constructor must call Show's constructor. Since you didn't call Show's three argument constructor explictly, Show must provide a default constructor. However, Show does not have a default constructor. That is what the compiler error is trying to tell you.

Edit: corrected references to Show.


Last edited on
On an unrelated note - I would suggest thinking about exactly what a 'Show' is supposed to represent, and how you would classify what a 'Performer' and a 'Musician' represents.


Currently every one of your 'Show' objects are storing a list<Show> within the Show class itself. This suggests that a Show can contain many Shows, which in turn can each contain many Shows, etc ad infinitum.

It seems to me that a 'Performer' and a 'Musician' would be a separate entity completely unrelated to Show - perhaps you're intending to create Performer and Musician as seperate classes and store List<Performer> and List<Musician> instead?
Topic archived. No new replies allowed.