-
Notifications
You must be signed in to change notification settings - Fork 38
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
Adding completed Vector files #3
Conversation
homework01/rudolf/vector.cpp
Outdated
|
||
Vector::Vector() | ||
{ | ||
mX=0; |
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.
As discussed Thursday, it's good practice to use initializer list. About the style, our (Optiver) style is mX = 0;
homework01/rudolf/vector.cpp
Outdated
mY=0; | ||
} | ||
|
||
Vector::Vector(double x, double y): mX(x), mY(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.
You could call this constructor from the other one, see delgating constructor: https://en.cppreference.com/w/cpp/language/initializer_list#Delegating_constructor
homework01/rudolf/vector.cpp
Outdated
mY=0; | ||
} | ||
|
||
Vector::Vector(double x, double y): mX(x), mY(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.
Style: we would write this:
Vector::Vector(double x, double y) :
mX(x),
mY(y)
{}
homework01/rudolf/vector.cpp
Outdated
|
||
Vector::Vector(double x, double y): mX(x), mY(y){} | ||
|
||
double Vector::dotProduct(const Vector& vec) const |
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.
Good to see the argument passed as const ref and the constness of this method! It should be DotProduct
though ;)
homework01/rudolf/vector.cpp
Outdated
|
||
Vector::Vector(double x, double y): mX(x), mY(y){} | ||
|
||
double Vector::dotProduct(const Vector& vec) const |
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.
Also: in general we like writing as little code as possible - the best code is the one that does not exist.
homework01/rudolf/vector.cpp
Outdated
{ | ||
return true; | ||
} | ||
return false; |
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.
2 things: mixing mX
and GetX
is slightly disturbing, use one or the other. Also, you simply write:
return mX == v.mX && mY == v.mY;
homework01/rudolf/vector.cpp
Outdated
this->mY =v.GetY(); | ||
} | ||
// Overload == operator. | ||
bool Vector::operator==(const Vector& v) |
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.
This method should be const
homework01/rudolf/vector.h
Outdated
@@ -0,0 +1,31 @@ | |||
#ifndef __VECTOR_H_INCLUDED__ // if x.h hasn't been included yet... | |||
#define __VECTOR_H_INCLUDED__ // #define this so the compiler knows it has been included |
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.
We usually use #pragma once
, it's shorter and you cannot have collisions on the name.
homework01/rudolf/vector.h
Outdated
#ifndef __VECTOR_H_INCLUDED__ // if x.h hasn't been included yet... | ||
#define __VECTOR_H_INCLUDED__ // #define this so the compiler knows it has been included | ||
|
||
#include <iostream> |
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.
Please remove this include, this Vector class does not depend on anything from it.
homework01/rudolf/vector.h
Outdated
// Overload = operator. | ||
void operator=(const Vector& v); | ||
// Overload == operator. | ||
bool operator==(const Vector& v); |
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.
It's time to spend some time in the indentation settings of your favorite IDE :)
No description provided.