15,918,404 members
See more:
i'm having trouble with errors that are definition of implicitly-declared
```vec2::vec2()
{
x = 1.0f;
y = 2.0f;
}```

and
another error that is no declaration matches
```vec2::vec2(const float& x, const float& y) {
this->x = x;
this->y = y;
}```

in vec2.cpp
``` vec2& vec2::operator+=(const vec2& other)
{
}
vec2& vec2::operator-=(const vec2& other)
{
return subtract(other);
}
vec2& vec2::operator*=(const vec2& other)
{
return multiply(other);
}
vec2& vec2::operator/=(const vec2& other)
{
return divide(other);
}```

C++
`vec2& vec2::operator==(const vec2& other)`

even though i got the addition operator and subraction operator to work after time but now i still cant get the multiply operator to work and the divide operator to work
because it still says that there no matching declaration even though i properly have a copy of the function in the header file for it and the same with
```vec2::vec2()
{
x = 1.0f;
y = 2.0f;
}```

and
```vec2::vec2(const float& x, const float& y) {
this->x = x;
this->y = y;
}```
.

What I have tried:

```#include <iostream>
#include <vector>
using namespace std;

// this should be inside the header file
namespace sparky
{
namespace maths
{
struct vec2
{
public:
float x, y;
vec2();
vec2(const float& x, const float& y);

vector <int> v;

vec2 & add( const vec2 & other)
{
for (size_t n=0; n<v.size() && n<other.v.size(); ++n)
{
v[n] += other.v[n];
}
return *this;
}
vec2 & subtract( const vec2 & other)
{
for (size_t n=0; n>v.size() && n>other.v.size(); --n)
{
v[n] -= other.v[n];
}
return *this;
}
vec2 & multiply( const vec2 & other)
{
for (size_t n=0; n<v.size() && n<other.v.size(); ++n)
{
v[n] *= other.v[n];
}
return *this;
}
vec2 & divide( const vec2 & other)
{
for (size_t n=0; n>v.size() && n>other.v.size(); --n)
{
v[n] *= other.v[n];
}

return *this;
}

public:

vec2 & operator += ( const vec2 & other );
vec2 & operator -= ( const vec2 & other );
bool operator==(const vec2& other);
vec2 & operator *= ( const vec2 & other );
vec2 & operator /= ( const vec2 & other );

void push_back(const int i){ v.push_back(i); }

friend ostream & operator << ( ostream & os, const vec2 & v1);

};
}
}```

```#include "vec2.h"

namespace sparky
{
namespace maths
{
vec2::vec2()
{
x = 1.0f;
y = 2.0f;
}
vec2::vec2(const float& x, const float& y) {
this->x = x;
this->y = y;
}

ostream & operator << (ostream & os, const vec2 & v2)
{
for (const auto &  x : v2.v)
os << x << " ";
return os;
}
vec2& vec2::operator+=(const vec2& other)
{
}
vec2& vec2::operator-=(const vec2& other)
{
return subtract(other);
}
vec2& vec2::operator*=(const vec2& other)
{
return multiply(other);
}
vec2& vec2::operator/=(const vec2& other)
{
return divide(other);
}

}
}```

```#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <GL/glu.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#define GLEW_STATIC
#include <GL/gl.h>
#include <iostream>
#include <math.h>

#include "vec2.h"
#include "window.h"
#define __gl_h_

#define GLFW_DLL```

int main() {
```vec2 a(1.0f,2.0f);
vec2 b(2, 4);
a -= b;
}```
Posted
Updated 22-Jul-21 21:39pm
v3