Constructor error

Why do I get the error "no default constructor exists for class "Face"?
I thought the Face(Point c, int r) function was the constructor in Emoji.h, and the EmptyFace(Point c1, Point c2, int r) was the constructor in EmptyFace.h.
I have commented in the code where the error is.

Emoji.h:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #pragma once


// Include Graph_lib library files that holds declarations needed for Window,
// and Shape derivatives.
#include "Graph.h"
#include "GUI.h"

// This part is only relevant for non-Windows users in 2019.
// Windows users has Graph_lib::Arc, Mac don't.
#ifndef WIN32
#include "Graph_lib.h"
#endif

using namespace Graph_lib;

// An abstract class. Concrete classes derived from this base class
// has to implement the member function attach_to().
class Emoji
{
public:
	// Disable copying. Disable slicing, etc.
	Emoji(const Emoji&) = delete;
	Emoji& operator=(const Emoji&) = delete;

	// Deleting the copy constructor also deletes the default constructor.
	// Emoji needs a default constructor.
	Emoji() {}
	// Emoji() = default; // is an alternative way of achieving the same.

	// The pure virtual function that has to be overriden for a deriving class
	// to be instantiable. Every class deriving from Emoji is supposed to
	// attach all its Shapes to a window. This makes the class abstract.
	virtual void attach_to(Graph_lib::Window&) = 0;

	// Relevant because Vector_ref can own Emojis and automatically cleans up.
	// Subject will be visited later in the course.
	virtual ~Emoji() {}
};

// A yellow, empty face.
// An abstract class.
class Face : public Emoji
{
private:
	/* TODO:
	 *  - add shapes (private)
	 *  - make the class abstract
	 **/
	Circle c1;
public:
	Face(Point c, int r) :c1{ c,r } {};
	void attach_to(Graph_lib::Window& win) override;
};


Emoji.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Emoji.h"
#include "std_lib_facilities.h"

// A yellow, empty face.
Face::Face(Point c, int r):c1{c,r}
{
	c1.set_fill_color(Color::yellow);

	cout << "Not yet implemented\n";
}

void Face::attach_to(Graph_lib::Window& win)
{
	win.attach(c1);
}


EmptyFace.h:
1
2
3
4
5
6
7
8
9
10
11
12
#include "Emoji.h"
#include "std_lib_facilities.h"

class EmptyFace :public Face {
private:
	Circle leftEye;
	Circle rightEye;
public:
	EmptyFace(Point c1, Point c2, int r) :leftEye{ c1,r }, rightEye{ c2,r } "{"}; 
//The first bracket in the last bracket parenthesis pair marked inside the quotation marks is 
//where the red line is, and when I hover over I get the error I explained in the start.
};


Haven't started to make EmptyFace.cpp yet..
Last edited on
The default constructor for any class is:
classname()

So for your class Face, the default constructor is
Face()

That constuctor does not exist.

Your class EmptyFace must call a Face constructor. Because you haven't specified what Face constructor to call, the default Face constructor is called. But that doesn't exist.
Thanks for answering!
Hmm okay, I think I get what you're saying, but why does EmptyFace need a Face constructor?
Face didn't need a Emoji constructor (at least not that i'm aware of) even though it is derived from the Emoji class.

And how do I specify the Face constructor in the Emptyface class?
why does EmptyFace need a Face constructor?

EmptyFace must be constructed. There are bits of EmptyFace that came from Face. These too must be constructed. To create the EmptyFace object, a Face constructor will be called, and then an EmptyFace constructor will be called. This is how C++ works.

Face didn't need a Emoji constructor (at least not that i'm aware of)

Face's constructor does not specify which Emoji constructor to call, so the default Emoji constructor will be called. Does that default Emoji constructor exist? Yes. It does.

And how do I specify the Face constructor in the Emptyface class?
EmptyFace(Point c1, Point c2, int r) : Face ( some_Point_value, some_int_value ) , leftEye{ c1,r }, rightEye{ c2,r } "{"};
Don't forget to provide the needed Point and int values for the Face constructor.
I see, I see..
Thanks a lot!
Topic archived. No new replies allowed.