[Cg1] CPP Header files and local instances of classes

Julian Klein s9jiklei at stud.uni-saarland.de
Thu Nov 1 14:16:26 CET 2018


Dear everybody,

I am pretty confused about part of the homework:

Let's take Vector.h for example.

We are supposed to implement Vector.

If we look at the header file, we see two types of method stubs (how do 
you call that again properly?): The ones inside the scope of the class 
Vector and the ones OUTSIDE of that scope.

What's the difference between those?

Also, the operators: Let's take a look at operator+(const Vector& b) 
const, which is binary.

But it has only one argument. When trying to access the variables of the 
current class (to use the binary operator when only one argument is 
passed in the method), I have to create a new local instance of the 
class inside the implementation of the operator. Can that be right? I 
think this is super weird, because I am returning a new instance of the 
class! Should I do this differently or is this not a problem?


Best,

j



More information about the Cg1 mailing list