C2039 “calculateFitness”: 不是“std::vector<Individual,std::allocator<_Ty>>”的成员
时间: 2024-01-22 13:03:56 浏览: 24
函数或方法
这个错误通常是由于在代码中使用了一个类的成员函数或方法,但是该函数或方法并不存在于该类中。在本例中,该错误意味着您正在尝试在“std::vector<Individual,std::allocator<_Ty>>”类中调用一个名为“calculateFitness”的函数,但是该函数并不存在于该类中。
要解决这个错误,您需要检查代码中使用的类和函数,并确保它们存在于正确的位置。您可能需要查看您的类定义和头文件,以确保函数被正确声明和定义。如果您是从其他代码中复制和粘贴代码,那么可能是因为您未正确包含所需的头文件或命名空间。
相关问题
没有与这些操作数匹配的 "=" 运算符C/C++(349) listener_str.cpp(12, 23): 操作数类型为: std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>> = std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>>
这个错误通常是因为尝试将一个类型为`std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>>`的变量赋值给一个类型为`std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>>`的变量,这两个类型虽然都是指向`rclcpp::Subscription`的`shared_ptr`,但是模板参数不同,无法直接赋值。
解决方法是将两个类型匹配,可以通过使用`std::static_pointer_cast`将其中一个类型转换成另一个类型,例如:
```
std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>> sub;
std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>> sub_const;
// 将 sub_const 转换成 sub 的类型
sub = std::static_pointer_cast<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>>(sub_const);
```
imuState<S> imu_state_; std::vector<camState<S>> cam_states_; std::vector<camState<S>> pruned_states_; std::vector<Vector3<S>, Eigen::aligned_allocator<Vector3<S>>> map_; imuState<S> imu_state_; std::vector<camState<S>> cam_states_; std::vector<camState<S>> pruned_states_; std::vector<Vector3<S>, Eigen::aligned_allocator<Vector3<S>>> map_;
这是一段 C++ 代码,其中定义了一个模板类,类名为 imuState,模板参数 S 表示数据类型。类中有四个成员变量:一个 imuState 类型的 imu_state_,一个 vector 类型的 cam_states_,一个 vector 类型的 pruned_states_,以及一个 vector 类型的 map_,其中 map_ 的元素类型为 Vector3<S>,并使用 Eigen 库的 aligned_allocator。
这个类的具体实现需要查看更多代码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)