LSystemオブジェクトの初期化時にL-Systemの構造体を実装しようとしましたが、エラーが発生しました。コンストラクタに問題があるようです。私が取得C++ 11:コンストラクタへの呼び出しで一致する関数がありません
#include <iostream>
#include <string>
#include <vector>
#include "LSystem.h"
int main() {
/*
2.1 Koch curve
variables : F
constants : + -
start: F
rules: F ! F+F-F-F+F
F means "draw while moving one step forward", + means "turn left 90°", - means
"turn right 90°"
*/
unsigned int rounds = 5;
unsigned int counter = 0;
std::vector<std::string> Kvar = {"F"};
std::vector<std::string> Kcons = {"+", "-"};
std::string Kstart = {"F"};
std::vector< std::vector<std::string> > Krules = { {"F", "+", "F", "-", "F", "-", "F", "+", "F"} }; //have to be in the same order as their variables in var_
LSystem Koch = LSystem(Kvar, Kcons, Kstart, Krules, counter); // line with error
while (Koch.counter_ < rounds) {
Koch.apply();
Koch.print_state();
}
}
:
ヘッダファイルLSystem.h:
#include <vector>
#include <string>
struct LSystem {
// member variable
//-----------------------------------------------
std::vector<std::string> var_;
std::vector<std::string> cons_;
std::vector<std::string> axiom_;
std::vector< std::vector<std::string> > rules_; //have to be in the same order as their variables in var_
unsigned int counter_;
// ctor
//-----------------------------------------------
// parameterless ctor
//LSystem();
// parameterized ctor
LSystem (const std::vector<std::string> &var, const std::vector<std::string> &cons,
const std::vector<std::string> &axiom, const std::vector< std::vector<std::string> > &rules,
const unsigned int counter);
// copy ctor
LSystem (const LSystem &s);
// member-functions
//-----------------------------------------------
void apply();
void print_state() const;
};
ソースコードファイルLSystem.cpp:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // std::find
#include <iterator>
#include "LSystem.h"
//Ctor
LSystem::LSystem(const std::vector<std::string> &var,
const std::vector<std::string> &cons,
const std::vector<std::string> &axiom,
const std::vector< std::vector<std::string> > &rules,
const unsigned int counter)
: var_ {var}, cons_ {cons}, axiom_ {axiom}, rules_ {rules}, counter_ {counter} { }
LSystem::LSystem (const LSystem &s)
: var_ {s.var_}, cons_ {s.cons_}, axiom_ {s.axiom_}, rules_ {s.rules_}, counter_ {s.counter_} { }
//member functions
//apply: applies the rule on the current axiom
void LSystem::apply() {
std::vector<std::string> tmp;
for (std::string s1 : axiom_) {
unsigned int pos = std::find(var_.begin(), var_.end(), s1) - var_.begin();
for (std::string s2 : rules_[pos]) {
tmp.push_back(s2);
}
}
axiom_ = tmp;
counter_ += 1;
}
//print_stat: prints the current axiom
void LSystem::print_state() const {
for (std::vector<std::string>::const_iterator i = axiom_.begin(); i != axiom_.end(); ++i)
std::cout << *i << " ";
}
メインファイルMAIN.CPP Main.cppに示されている行のエラー
no matching function for call to ‘LSystem::LSystem(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, std::__cxx11::string&, std::vector<std::vector<std::__cxx11::basic_string<char> > >&, unsigned int&)’ LSystem Koch = LSystem(Kvar, Kcons, Kstart, Krules, counter);
私はC++の初心者です。コンストラクタに何が間違っているのか本当に分かりません。また、パラメータのないコンストラクタが必要かどうかもわかりません。
ありがとうございます!
ありがとうございました!私はなぜ私の質問のために下落したのですか?私は自分自身を明確に表現し、完全な記録を提供したと思った... – Linda