-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
L07 zadanie domowe - I czesc #2
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+15 punktów na 18
Add new field: Color color in Shape class, so that every shape has it's own | ||
defined color. | ||
to do-> trzeba zrobic konstruktor klasy bazowe, pozmieniac wszytskei konstruktory | ||
klas pochodnych i zmienic w main wywolywanie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeśli konstruktor klasy bazowej będzie miał parametr Color, to można mu też przypisać wartość domyślną, dzięki czemu nie trzeba będzie zmianiać wszystkich konstruktorów klas pochodnych.
|
||
struct PIValueCheckn // zad 1 | ||
{ | ||
static_assert(M_PI != 3.14, "M_PI defined in math library is not equal to 3.14"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tylko informacyjnie - to można nawet poza strukturą użyć, w zupełnie dowolnym kawałku kodu
{if(s) return (s->getArea() < 10); | ||
return false;}; | ||
|
||
auto areaLessThanX= [](int x = 10, Shape* s) //<-- shoule be int x = 10 declarated here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it should be on a capture list [x = 10]
@@ -65,7 +57,7 @@ void findFirstShapeMatchingPredicate(const Collection& collection, | |||
std::string info) | |||
{ | |||
Collection::const_iterator iter = std::find_if(collection.begin(), collection.end(), predicate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iter can be auto as well
shapes.push_back(new Rectangle(10.0, 5.0)); | ||
shapes.push_back(new Square(3.0)); | ||
shapes.push_back(new Circle(4.0)); | ||
std::cout<<FibonacciNumber(45)<<std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aby mieć pewność że to się liczy w czasie kompilacji to wynik trzeba by było zapisać do stałej constexpr. Np g++ w wersji poniżej 9 z tego co mi wiadomo tutaj nie zrobi tego w czasie kompilacji.
constexpr int result = FibonacciNumber(45);
std::cout << result <<std::endl;
std::cout<<"Alignof Circle: "<<alignof(obj)<<std::endl; | ||
Circle new_obj(std::shared_ptr<Circle> obj); | ||
Collection shapes = {new Circle(2.0), | ||
// std::shared_ptr<Circle> (new double(2.0)), <-- cam I use it in construcotr? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tak, ale bez żadnych new, bo Circle przyjmuje double, a nie double*
std::shared_ptr<Circle>(2.0)
{ | ||
//x_=object.getX(); <-- ??? | ||
return *this; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
najlepsza implementacja konstruktora i operatora przenoszącego to = default;
w pliku hpp.
Jeśli nie chcesz używać default, to tutaj powinno być
x_ = std::move(object.x_)
x_ = other.getX(); | ||
y_ = other.getY(); | ||
x_=object.x_; | ||
y_=object.y_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
powinno być y_ = std::move(object.y_);
i tak samo x_.
A jeszcze lepiej = default;
@@ -32,3 +41,13 @@ void Circle::print() const | |||
<< " area: " << getArea() << std::endl | |||
<< " perimeter: " << getPerimeter() << std::endl; | |||
} | |||
|
|||
[[deprecated]]double Circle::getPi() //zad 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lepiej jest użyć deprecated w pliku hpp. Wtedy informacja że ta funkcja jest przestarzała będzie dostępna w każdym pliku, który robi #include "Circle.hpp"
|
||
8. override, final: | ||
Mark Circle class as final | ||
Mark getX() in Rectangle as final // nie można tego dopisac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nie można, bo trzeba jeszcze dopisać virtual. final może być użyte tylko na funkcjach wirtualnych.
No description provided.