0
Help with homework
How to make_unique and return a unique_ptr.
4 Respostas
+ 4
Can you specify the task better please?
+ 2
I'm not sure how the data for your shapes are supposed to be, so I just specified the Points belonging to them. The rectangle is not guaranteed to be 90 deg, so it should probably just be a considered as general quadrangle. More complicated constuctors are probably needed, but that is not the focus of this exercise.
Anyway, this is how I would do it. It might not be what you're after but perhaps it will give you some ideas.
I also added an extra experimental method to generate a random pick of shape from a single method, returning a custom type based on std::variant.
https://sololearn.com/compiler-playground/cj4dFB6I0zm0/?ref=app
+ 1
It says “Create a class called ShapeFactory. Add 7 static methods: a method for creating a random point, a method for creating a random color, and methods for creating unique pointers for each Shape type (Shape, Line, Rectangle, Triangle, Circle). The methods that create the random Shapes should use make_unique and return a unique_ptr.” I just need an example
+ 1
Check this link, much better than anything:
https://www.w3schools.com/cpp/cpp_class_methods.asp
https://sololearn.com/compiler-playground/cD3zCE4Ycut5/?ref=app
https://sololearn.com/compiler-playground/cjOqjY34lbmO/?ref=app
Why don't you attached your attempts with the code? Do try first this is your problem! Attached your effort, we will solve the rest..