Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

croosthuizen
Copy link
Contributor

No description provided.


Vector::Vector()
{
mX=0;
Copy link
Owner

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;

mY=0;
}

Vector::Vector(double x, double y): mX(x), mY(y){}
Copy link
Owner

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

mY=0;
}

Vector::Vector(double x, double y): mX(x), mY(y){}
Copy link
Owner

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)
{}


Vector::Vector(double x, double y): mX(x), mY(y){}

double Vector::dotProduct(const Vector& vec) const
Copy link
Owner

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 ;)


Vector::Vector(double x, double y): mX(x), mY(y){}

double Vector::dotProduct(const Vector& vec) const
Copy link
Owner

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.

{
return true;
}
return false;
Copy link
Owner

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;

this->mY =v.GetY();
}
// Overload == operator.
bool Vector::operator==(const Vector& v)
Copy link
Owner

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

@@ -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
Copy link
Owner

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.

#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>
Copy link
Owner

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.

// Overload = operator.
void operator=(const Vector& v);
// Overload == operator.
bool operator==(const Vector& v);
Copy link
Owner

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 :)

david-grs pushed a commit that referenced this pull request Nov 19, 2018
david-grs pushed a commit that referenced this pull request Nov 19, 2018
david-grs pushed a commit that referenced this pull request Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants