Community,
I'm completly new to c++ so I hope you can help me. I've already written in Java and there are plenty of similarities, but I can't understand this error. It seems, that in the Constructor of my PrimitiveBase.cpp the compiler interprets the Type Colour as a constructor with no arguments, which I don't have. When I define a second Constructor with no arguments and no functionality the error is gone. But that doesn't match with my understanding of parameter decleration for functions.
Her is the error:
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/PrimitiveBase.cpp: In constructor 'PrimitiveBase::PrimitiveBase(std::vector<Coordinate>, Colour)':
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/PrimitiveBase.cpp:5:74: error: no matching function for call to 'Colour::Colour()'
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/PrimitiveBase.cpp:5:74: note: candidates are:
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/Colour.hh:9:2: note: Colour::Colour(int, int, int, std::string)
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/Colour.hh:9:2: note: candidate expects 4 arguments, 0 provided
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/Colour.hh:6:7: note: Colour::Colour(const Colour&)
/home/christian/Documents/EBV/ebv-S03-G01/src/Graphics2D/Colour.hh:6:7: note: candidate expects 1 argument, 0 provided
Here the code you might need: PrimitiveBase.cpp
#include <Graphics2D/PrimitiveBase.hh>
#include <Graphics2D/Coordinate.hh>
#include <Graphics2D/Colour.hh>
PrimitiveBase::PrimitiveBase(std::vector<Coordinate> coord, Colour colour) { //Here the error happens
this->coord=coord;
this->colour=colour;
}
Colour PrimitiveBase::GetColour() {
return colour;
}
std::vector<Coordinate> PrimitiveBase::GetCoordinates() {
return coord;
}
void PrimitiveBase::SetColour(int red, int green, int blue) {
colour.SetColours(red,green,blue);
}
void PrimitiveBase::SetCoordinates(std::vector<Coordinate> newCoord) {
coord = newCoord;
}
Colour.hh
#ifndef COLOUR_HH_
#define COLOUR_HH_
#include <string>
class Colour {
public:
Colour(int red, int green, int blue, std::string name);
//Colour(){}; Constructo I seem to need
//~Colour();
void SetColours(int red, int green, int blue);
static Colour black();
static Colour red();
static Colour green();
static Colour blue();
private:
std::string name;
unsigned char rgb[3];
};
#endif
I really don't understand, cause I did this for the last 2 years in Java and in the last exercises it also worked in c++.
Would be very glad if you could help me :)