英文:
Undeclared identifier error, but variable correctly defined (?)
问题
I've been using the same files for a while now, but suddenly making some other changes, this error started popping up
constraints.cpp:105:5: error: use of undeclared identifier 'constraintViolated';
'constraintViolated' was not declared in scope
I followed quite a few answers in the above thread but didn't seem relevant in my case. I'm not sure if there's something else triggering this. Clearly I've declared the variables in the header but they don't seem to have been read in the cpp file. In fact, there are other variables that do the same, but I'll limit my example to this. The code worked perfectly before, but some minor modifications have made this error pop up.
Could it be a build issue?
I've tried to add all the relevant code. The code is below,
constraints.cpp
namespace tudat{
Constraint::Constraint(std::string filenameForConstraintData){
constraintViolated = 0;
constraintLengthVehicle = 0.0;
constraintDiameterVehicle = 2.44;
}
void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle, Eigen::Vector3d diameterMotorCaseStage,
Eigen::Vector3d diameterNozzleExitStage, Eigen::Vector3d lengthMotorCaseStage){
constraintViolated = 0;
constraintLengthVehicle = 25.0;
constraintDiameterVehicle = 2.44;
if (totalLengthOfTheVehicle/diameterMotorCaseStage1 > maxLOverDRatio){
constraintViolated = 1;
if (printConstraints_ == 1){
std::cout<< "Length is"<< totalLengthOfTheVehicle << std::endl;
}
}
}
constraints.h
namespace tudat
{
class Constraint{
public:
Constraint(std::string filenameForConstraintData);
int getConstraintViolated(){ return constraintViolated; }
// void checkTrajectoryConstraints(const std::vector< tudat::basic_astrodynamics::AccelerationModel3dPointer > listOfAccelerationsActingOnLaunchVehicle,
// const boost::shared_ptr< tudat::RocketLaunchVehicle > launchVehicle,
// const boost::shared_ptr< EnvironmentUpdater > environmentUpdater);
// void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle,
// double diameterMotorCaseStage1, double diameterMotorCaseStage2, double diameterMotorCaseStage3,// double diameterMotorCaseStage4,
// double diameterNozzleExitStage1,double diameterNozzleExitStage2, double diameterNozzleExitStage3, // double diameterNozzleExitStage4,
/* double vacuumThrustStage1, double massStartStage1, double deltaVVehicle, double vacuumThrfustStage3, */
// double lengthMotorCaseStage1, double lengthMotorCaseStage2, double lengthMotorCaseStage3 ); //, double lengthMotorCaseStage4);
void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle,
Eigen::Vector3d diameterMotorCaseStage,
Eigen::Vector3d diameterNozzleExitStage,
Eigen::Vector3d lengthMotorCaseStage);
private:
int constraintViolated;
int printConstraints_;
英文:
I've been using the same files for a while now, but suddenly making some other changes, this error started popping up
constraints.cpp:105:5: error: use of undeclared identifier 'constraintViolated';
'constraintViolated' was not declared in scope
I followed quite a few answers in the above thread but didn;t seem relevant in my case. I'm not sure if there's something else triggering this. Clearly I've declared the variables in the header but they dont seem to have been read in the cpp file. In fact, there are other variables that do the same,but i'll limit my example to this. The code worked perfectly before, but some minor modifications have made this error pop up.
Could it be a build issue?
I've tried to add all the relevant code. The code is below,
constraints.cpp
namespace tudat{
Constraint::Constraint(std::string filenameForConstraintData){
constraintViolated = 0;
constraintLengthVehicle = 0.0;
constraintDiameterVehicle = 2.44;
}
void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle, Eigen::Vector3d diameterMotorCaseStage,
Eigen::Vector3d diameterNozzleExitStage, Eigen::Vector3d lengthMotorCaseStage){
constraintViolated = 0;
constraintLengthVehicle = 25.0;
constraintDiameterVehicle = 2.44;
if (totalLengthOfTheVehicle/diameterMotorCaseStage1 > maxLOverDRatio){
constraintViolated = 1;
if (printConstraints_ == 1){
std::cout<< "Length is"<< totalLengthOfTheVehicle << std::endl;
}
}
}
constraints.h
namespace tudat
{
class Constraint{
public:
Constraint(std::string filenameForConstraintData);
int getConstraintViolated(){ return constraintViolated; }
// void checkTrajectoryConstraints(const std::vector< tudat::basic_astrodynamics::AccelerationModel3dPointer > listOfAccelerationsActingOnLaunchVehicle,
// const boost::shared_ptr< tudat::RocketLaunchVehicle > launchVehicle,
// const boost::shared_ptr< EnvironmentUpdater > environmentUpdater);
// void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle,
// double diameterMotorCaseStage1, double diameterMotorCaseStage2, double diameterMotorCaseStage3,// double diameterMotorCaseStage4,
// double diameterNozzleExitStage1,double diameterNozzleExitStage2, double diameterNozzleExitStage3, // double diameterNozzleExitStage4,
/* double vacuumThrustStage1, double massStartStage1, double deltaVVehicle, double vacuumThrfustStage3, */
// double lengthMotorCaseStage1, double lengthMotorCaseStage2, double lengthMotorCaseStage3 ); //, double lengthMotorCaseStage4);
void checkVehicleConstraints(int launchVehicleType, int numberOfStages, double lengthVehicle, double diameterVehicle,
Eigen::Vector3d diameterMotorCaseStage,
Eigen::Vector3d diameterNozzleExitStage,
Eigen::Vector3d lengthMotorCaseStage);
private:
int constraintViolated;
int printConstraints_;
答案1
得分: 1
使用作用域分辨符来告诉编译器,你的 checkVehicleConstraints
实现属于 Constraint
,因为你不在 constraints.cpp
中的类内部:
void Constraint::checkVehicleConstraints(int launchVehicleType, ...
这样它就可以访问 Constraint
的私有成员。
英文:
Use a scope resolution modifier to tell the compiler that your checkVehicleConstraints
implementation is the one belonging to Constraint
since you're not within the class in your constraints.cpp
:
void Constraint::checkVehicleConstraints(int launchVehicleType, ...
That way it'll have access to Constraint
's private members.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论