) Ich habe ein Problem, das sehr einfach zu lösen wäre, aber ich kann nicht den richtigen Formalismus in C++ finden. Ich möchte ein Objekt einer anderen Klasse die angegebene Header-Datei deklarieren. Leider bekomme ich den Fehler:Deklaration eines Objekts in einer anderen Header-Datei
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
calc/solver_nonl/new_raphs.cpp: In constructor
‘new_raphs::new_raphs(Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd)’:
calc/solver_nonl/new_raphs.cpp:7:44: error: no matching function for call to ‘stiff_nonl::stiff_nonl()’
:set_force(node_matrix,dof_matrix_input)
^
calc/solver_nonl/new_raphs.cpp:7:44: note: candidates are:
In file included from calc/solver_nonl/new_raphs.h:8:0,
from calc/solver_nonl/new_raphs.cpp:1:
calc/solver_nonl/../fem_nonl/stiff_nonl.h:20:5: note: stiff_nonl::stiff_nonl(Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd)
stiff_nonl(MatrixXd node_matrix, MatrixXd dof_matrix_input, MatrixXd element_matrix, MatrixXd element_info_matrix);
^
calc/solver_nonl/../fem_nonl/stiff_nonl.h:20:5: note: candidate expects 4 arguments, 0 provided
calc/solver_nonl/../fem_nonl/stiff_nonl.h:17:7: note:
stiff_nonl::stiff_nonl(const stiff_nonl&)
class stiff_nonl : public set_force
^
calc/solver_nonl/../fem_nonl/stiff_nonl.h:17:7: note: candidate expects 1 argument, 0 provided
calc/solver_nonl/new_raphs.cpp: In member function ‘Eigen::MatrixXd& new_raphs::get_epsilon_results(int, int)’:
calc/solver_nonl/new_raphs.cpp:92:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
make: *** [all] Fehler 1
Ich habe Objekte von verschiedenen Klassen oft vorher erklärt, aber was mache ich hier falsch?
Die Header-Datei sieht wie folgt aus:
#ifndef NEW_RAPHS_H
#define NEW_RAPHS_H
# include "../../pre/boundary_force/set_force.h"
# include <iostream>
#include "../fem_lin/stiff.h"
#include "../fem_nonl/stiff_nonl.h"
using namespace std;
class new_raphs : set_force
{
public:
new_raphs(MatrixXd node_matrix, MatrixXd dof_matrix_input, MatrixXd element_matrix, MatrixXd element_info_matrix, MatrixXd force_matrix_input);
MatrixXd elements;
MatrixXd elements_info;
MatrixXd force_matrix;
void calc();
VectorXd U;
MatrixXd res;
MatrixXd result_matrix;
MatrixXd &get_result();
stiff_nonl stiffness_nonl; // here is the bug!
MatrixXd &get_epsilon_results(int noe, int num_gauss_point);
};
#endif // NEW_RAPHS_H
Er obviousely wie die Erklärung tut stiff_nonl stiffness_nonl; ??? Hat es etwas zu tun, dass die steif_nonl-Klasse von einer anderen Klasse erbt? Muss ich das in der Erklärung berücksichtigen?
Hoffe einer der C++ Checker kann mir hier helfen?
Vielen Dank im Voraus!
Prost Franz
Geben '' stiff_nonl ein Default-Konstruktor (ohne Argument) oder die richtigen Argumente werden wahrscheinlich Ihr Problem lösen. HINWEIS: Es ist üblich, das erste Zeichen eines jeden Wortes bei der Namensgebung zu typisieren. "Steif_nonl" sollte wahrscheinlich "Stiff_Nonl" heißen. – George
Das Hinzufügen von stairness_nonl zur Initialisierungsliste des Konstruktors von new_raps hilft (eine etwas andere Lösung für das Problem, wie von George gezeigt) – stefaanv