コミュニティ、
私はC ++にまったく慣れていないので、助けていただければ幸いです。私はすでに Java で書いており、類似点はたくさんありますが、このエラーは理解できません。私の PrimitiveBase.cpp のコンストラクターでは、コンパイラーは Type Color を、私が持っていない引数のないコンストラクターとして解釈しているようです。引数も機能も持たない 2 番目のコンストラクターを定義すると、エラーはなくなりました。しかし、それは関数のパラメーター宣言に関する私の理解とは一致しません。
彼女はエラーです:
/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
必要なコードは次のとおりです: 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;
}
カラー.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
私は本当に理解できません.Javaで過去2年間これを行ったので、最後の演習ではc ++でも機能しました。
あなたが私を助けることができれば、とてもうれしいです:)