2016-10-20 4 views
0

) 해결하기가 매우 쉽지만 C++에서 올바른 형식주의를 찾을 수없는 문제가 있습니다. 주어진 헤더 파일의 다른 클래스의 객체를 선언하고 싶습니다. 불행히도 오류가 발생합니다 :다른 헤더 파일에있는 객체 선언

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 

자주 다른 클래스의 객체를 선언했지만 여기에 무엇이 잘못 되었습니까? 다음과 같이

헤더 파일은 같습니다

#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 

그는 obviousely 선언처럼 나던 stiff_nonl stiffness_nonl; ??? stiff_nonl 클래스가 다른 클래스에서 상속 받도록 할 일이 있습니까? 선언문에서 이것을 고려해야합니까?

C++ 검사기 중 하나가 여기에서 나를 도울 수 있으시겠습니까?

미리 감사드립니다.

건배 Franz

+0

는'stiff_nonl'(아무 인수 포함) 기본 생성자를 부여하거나 올바른 인수가 아마 당신의 문제를 해결할 것입니다 ... 나에게 조금 이상하다. 주의 : 타입을 명명 할 때 각 단어의 첫 문자를 캡쳐 화하는 것이 일반적입니다.'stiff_nonl'은 아마도'Stiff_Nonl'이어야합니다. – George

+0

아마도 stiffness_nonl을 new_raphs의 생성자 초기화 목록에 추가하면 도움이 될 것입니다. (George가 보여준 문제와 약간 다른 해결책) – stefaanv

답변

0

stiff_nonl에는 기본 생성자가 없습니다. 당신은 new_raphs 생성자 초기화 목록에서 예컨대을 올바른 인수를 전달할 수 있습니다 :

class new_raphs : public set_force 
0

와우 감사합니다 : 또한 당신이 여기에 공공 상속을 원했다는 것을 생각

new_raphs::new_raphs(MatrixXd node_matrix, MatrixXd dof_matrix_input, MatrixXd element_matrix, MatrixXd element_info_matrix, MatrixXd force_matrix_input) 
    : stiffness_nonl() //pass arguments to stiff_nonl constr. inside brackets 
{ 
    //... 
} 

! 지금은 작동합니다 :)

올바른 생성자이었다

난 아직도 조금 혼란 스러워요
new_raphs::new_raphs(MatrixXd node_matrix, MatrixXd dof_matrix_input, MatrixXd element_matrix, MatrixXd element_info_matrix, MatrixXd force_matrix_input) 

:set_force(node_matrix,dof_matrix_input), stiffness_nonl(node_matrix, dof_matrix_input, element_matrix, element_info_matrix) 

이유는 개체 이름 (stiffness_nonl)이 아닌 클래스 또는 생성자 이름 (stiff_nonl) ??? 이 건배 프란츠

+0

C++/객체 지향 프로그래밍 북을 읽어야합니다. 첫 번째 경우에는 기본 클래스 (set_force)에 인수를 전달하고 두 번째 클래스는 클래스 필드 (stiffness_nonl)를 초기화합니다. 클래스와 객체 (클래스의 인스턴스)의 차이점을 확인하고 상속에 대해 자세히 알아보십시오. – foxfireee

관련 문제