Fehlermeldung: expected unqualified-id before '/' token
-
Hallo,
ich bin in der Programmierung, wie einige Fragende, recht neu. Bei der Programmierung des unten stehenden Codes tritt der Fehler "error: expected unqualified-id before '/' token" sehr häufig auf. Leider weiß ich keine Antwort, um ihn zu beheben.
Ich habe erst den Header und dann den Code an sich.(Es ist alles Teil eines größeren Programms, soll sich aber auch so kompilieren lassen.)
Beste Grüße und vielen Dank schon mal!
#ifndef PROJECTILEMOTION_H #define PROJECTILEMOTION_H #include "physicalmodel.h" #include "data_read.h" #include <vector> #include <string> class projectileMotion : public PhysicalModel { //Methoden public: projectileMotion(); projectileMotion(data_storage& input); ~projectileMotion(); virtual std::vector<double> derivative(const std::vector<double>& y, double t); virtual std::vector<double> y0(); virtual std::vector<std::string> variables(); //Additional methods: //Trajectory virtual std::vector<double> trajec(const std::vector<double>& y, double t); //Acceleration virtual std::vector<double> acc(const std::vector<double>& y, double t); //Trajectorial vertex virtual std::vector<double> vertex(); //Total time double time(); //Total distance double dist(); private: std::vector<double> startValues; }; #endif
#include "projectileMotion.h" #include <cmath> #include <iostream> #include <vector> #include <string> #include <fstream> #include <stdio.h> #include <math.h> using namespace std; const double pi = 3.14159265; const double g = 9.81; //Standard-Konstruktor projectileMotion::projectileMotion() { cout << "Neue Instanz von 'projectileMotion' erzeugt."; startValues.push_back(10.); startValues.push_back(45.0); } //Konstruktor mit Vorgabewerten projectileMotion::projectileMotion(data_storage& input) { cout << "Neue Instanz von 'projectileMotion' erzeugt."; startValues.push_back(input.data_read_number_value("initial_velocity", "problem_parameters")); startValues.push_back(input.data_read_number_value("angle", "problem_parameters")); } //Destruktor projectileMotion::~projectileMotion() { cout << "Destruktor von 'projectileMotion'"; } //Zeitableitung zum Zeitpunkt t std::vector<double> projectileMotion::derivative(const std::vector<double>& y, double t) { std::vector<double> ddt; ddt.push_back(this->startValues.at(0) * cos(this->startValues.at(1) / 180 * pi)); ddt.push_back(-g * t + this->startValues.at(0) * sin(this->startValues.at(1) / 180 * pi)); return ddt; } //Anfangswerte der Zustandswerte std::vector<double> projectileMotion::y0() { std::vector<double> y; y.push_back(input.data_read_number_value("x_0", "problem_parameters")); y.push_back(input.data_read_number_value("y_0", "problem_parameters")); return y; } //Zustandsvariablen std::vector<std::string> projectileMotion::variables() { std::vector<std::string> n; n.push_back("x"); n.push_back("y"); return n; } //Trajectory std::vector<double> projectileMotion::trajec(const std::vector<double>& y, double t) { std::vector<double> traj; traj.push_back(this->startValues.at(0) * cos(this->startValues.at(1) / 180 * pi) * t); traj.push_back(-g / 2 * t * t + this->startValues.at(0) * sin(this->startValues.at(1) / 180 * pi) * t); return traj; } //Acceleration std::vector<double> projectileMotion::acc(const std::vector<double>& y, double t) { std::vector<double> acc; acc.push_back(.0); acc.push_back(-g); return acc; } //Trajectorial vertex std::vector<double> projectileMotion::vertex() { std::vector<double> vert; double con = this->startValues.at(0)*this->startValues.at(0) / g / 2; vert.push_back(con*sin(this->startValues.at(1) / 90 * pi)); vert.push_back(con*sin(this->startValues.at(1) / 180 * pi) * sin(this->startValues.at(1) / 180 * pi)); } //Total time double projectileMotion::time() { return this->startValues.at(0) * 2 * sin(this->startValues.at(1) / 180 * pi) / g; } //Total distance double projectileMotion::dist() { return this->startValues.at(0) * this->startValues.at(0) / g * cos(this->startValues.at(1) / 180 * pi)*2*sin(this->startValues.at(1)/180*pi); }
-
Mein Compiler sagt, in welcher Zeile die gemeldeten Fehler auftreten. "Sehr häufig" sagt er dagegen nie
-
Dein Fehler ist anderswo, aber nicht im gezeigten Code. Also wird der Fehler wohl in physicalmodel.h oder data_read.h sein.
Im gezeigten Code fehlt dagegen in
projectileMotion::vertex()
ein return-Statement.