No default constructor exist for class

Hello guys, when I've tried to create a constructor for class SmoothyCuFrica I receive this error "no default constructor exist for class DecoratorSmooty". Here is a diagram for easy understanding of my project https://gyazo.com/5ad2a44106d4969f5a7cf7e978291721.

1
2
3
4
5
6
7
8
9
10
11
  using namespace std;
class Smoothy {
private:
	int pret;
	
public:
	Smoothy() = default;
	virtual int getPret() { return pret; }
	virtual string descriere() = 0;

};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class BasicSmoothy :public Smoothy {
private:
	string nume;
public:
	BasicSmoothy(const string &nume) :nume{ nume } {}
	string descriere()override {
		if (nume == "capsuna") {
			return  "Smoothy capsune";
		}
		if (nume == "kiwi") {
			return "Smoothy kiwi";
		}

	}
	int getPret()override {
		if (nume == "capsuna") {
			return 10;
		}
		if (nume == "kiwi") {
			return 12;
		}
	}
};


1
2
3
4
5
6
7
8
9
10
11
12
13
class DecoratorSmoothy :public Smoothy {
private:
	BasicSmoothy s;
public:
	DecoratorSmoothy(const BasicSmoothy &s):s{s} {}
	string descriere()override {
		return s.descriere();
	}
	
	int getPret()override {
		return s.getPret();
	}
};


The problem is at SmoothyCuFrisca
1
2
3
4
5
6
7
8
9
10
11
12
class SmoothyCuFrisca :public DecoratorSmoothy {
private:
	DecoratorSmoothy s;
public:
	//SmoothyCuFrisca(const DecoratorSmoothy &s):s{s} {} PROBLEM IS HERE!
	string descriere()override {
		return s.descriere() + "cu frisca";
	}
	int getPret()override {
		return s.getPret() + 2;
	}
};
Last edited on
you said that you construct a decorator_smoothy like this DecoratorSmoothy(const BasicSmoothy &s), so you need to provide a basic_smoothy to it.
like the line that you have commented out.

By the way
1
2
3
class DecoratorSmoothy :public Smoothy {
private:
	BasicSmoothy s; //I don't see this in your diagram 
I don't know why that doesn't appear in the diagram,i use visual studio 2015 diagram generator, BasicSmoothy it's s in the new diagram,i think the problem it's because BasicSmoothy have a constructor with an argument and after that DecoratorSmoothy have another one and i need to make a new constructor for SmoothyCuFrisca but doesn't work the same way as DecorathorSmoothy. Anyway my main function will look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	int main() {
		vector<Smoothy*> lista;
		lista.push_back(new BasicSmoothy{ "kiwi" });
		lista.push_back(new BasicSmoothy{ "capsuna" });
		BasicSmoothy a{ "kiwi" };
                DecoratorSmothy b{ "capsuna" };
		lista.push_back(new DecoratorSmoothy{ a });
                lista.push_back(new SmoothyCuFrisca { b }); // that doesn't work because i don't know how to make a constructor to work like that
		for (auto smoothy : lista) {
			cout << smoothy->descriere() << "\n";
			cout << smoothy->getPret() << "\n";
		}
		return 0;

	}


new print of diagram https://gyazo.com/e8cab363351a0d5b64404c342b936ff9?token=80fedff16bbbf1556dfb5d1c885b573b
Last edited on
Topic archived. No new replies allowed.