Reputation: 119
I have the following problem already longer time. The point ist that I have read a bit on stackoverflow and I have used a typedef, but I doesnt help me.
Looking forward to get some help :)
Align_vector.h :
#include <utils/vector_2d.h>
class Vector_2d;
namespace Utils {
class Align_vector : public Vector_2d {
protected:
bool check_range(int x, int y);
public:
typedef enum {left, right, up, down} Alignment;
Align_vector(Alignment alignment);
void set_alignment(Alignment alignment);
Alignment get_alignment();
};
} /* namespace Utils */
Align_vector.cc :
#include <utils/align_vector.h>
namespace Utils {
Align_vector::Align_vector(Alignment alignment) {
this->alignment = alignment;
}
void set_alignment(Alignment alignment) {
Align_vector::alignment = alignment;
}
Alignment get_alignment() {
return Align_vector::alignment ;
}
bool check_range(int x, int y) {
switch ( Align_vector::alignment ) {
case Align_vector::left:
if (x == -1 && y == 0) {
return true;
} else {
return false;
}
break;
case Align_vector::right:
if (x == 1 && y == 0) {
return true;
} else {
return false;
}
break;
case Align_vector::down:
if (x == 0 && y == -1) {
return true;
} else {
return false;
}
break;
case Align_vector::up:
if (x == 0 && y == 1) {
return true;
} else {
return false;
}
break;
default:
return false;
break;
}
}
} /* namespace Utils */
Here is the error:
/utils/align_vector.cc:14:47: error: no matching function for call to ‘Utils::Vector_2d::Vector_2d()’ Align_vector::Align_vector(Alignment alignment) {
Upvotes: 1
Views: 881
Reputation: 4153
This code has numerous issues. First of all, you have defined an
enum
called Alignment
, but you did not declare a member
of that type. To do so, add this line after the definition of the enum
:
Alignment alignment;
Your definitions of methods are also incorrect, the alignment is supposed to belong to a specific object, while you are using it in several functions as if it were a static member of the class. Here are the fixed versions of method definitions:
namespace Utils {
Align_vector::Align_vector(Alignment alignment) {
this->alignment = alignment;
}
void Align_vector::set_alignment(Alignment alignment) {
this->alignment = alignment;
}
Align_vector::Alignment Align_vector::get_alignment() {
return this->alignment;
}
bool Align_vector::check_range(int x, int y) {
switch(this->alignment) {
case Align_vector::left:
if(x == -1 && y == 0) {
return true;
}
else {
return false;
}
break;
case Align_vector::right:
if(x == 1 && y == 0) {
return true;
}
else {
return false;
}
break;
case Align_vector::down:
if(x == 0 && y == -1) {
return true;
}
else {
return false;
}
break;
case Align_vector::up:
if(x == 0 && y == 1) {
return true;
}
else {
return false;
}
break;
default:
return false;
break;
}
}
} /* namespace Utils */
Finally, you are missing a definition of a default constructor for base
class Vector_2d
(your comments suggest that you did not define that class
at all, you just declared its existance using statement class Vector_2d;
).
Judging by your overall implementation, I think user @molbdnilo was correct
when suggesting you should learn more about C++ programming in general.
Hope this helps!
Upvotes: 2