c++11 - 试图 push_back 一个向量进入私有向量没有返回函数的同一个类
问题描述
我目前正在研究强化学习问题,我正在尝试添加元素的位置vector<State>
和vector<Action>
另一个浮点向量的位置哦继承类,这样我就可以操纵状态和动作的值。返回在 main 中的另一个函数上,所以我不能使用它。我正在尝试使用这个-> 但不工作。
渐变.h
class Gradient: virtual public Sarsa
{
public:
Gradient();
Gradient(float w);
//states with weights
std::vector<float> StateWeights(float s, float l, float a);
//from the actions vector will be created with weights
std::vector<float> ActionWeights(Action a);
void IsStateActionSeen();
private:
float w0,w1,w2,w3,w4,w5,w6;
std::vector<float> state_action_weights;
std::vector<float> StatesPos;
std::vector<float> Actions;
};
渐变.cpp
//returns the possition and the values of state in floationg points
std::vector<float> Gradient::StateWeights(float s, float l, float a)
{
std::vector<float> StateW;
//position of the state in the vector
int x = Sarsa::StateisNow ( s, l, a);//here i take the values of the main to find which state is not
float y = (float)(x);
std::cout<<"State found: "<<x<<std::endl;
//read the values of state from the position
State st = all_states.at(x);
std::cout<<"The State is: "<<st.get_pos()<<" "<<st.get_ang()<<" "<<st.get_spe()<<std::endl;
//create a vector with the values of the state and the weights
StateW={y, st.get_pos(),st.get_ang(),st.get_spe() };
std::cout<<"The State is: "<<StateW.at(0)<<" "<<StateW.at(1)<<" "<<StateW.at(2)<<" "<<StateW.at(3)<<std::endl;
this->StatesPos.push_back(&StateW);//i want to add it in the vector before it returns
return StateW;//return to the main
}
错误:没有匹配函数调用 'std::vector::push_back(std::vector*)' this->StatesPos.push_back(&StateW);
解决方案
StatePos
是浮点数的向量,您可以 push_back 仅浮点数(或将被隐式转换为浮点数的对象。
如果您需要附加两个向量,您可以执行以下操作:
StatePos.insert( StatePos.end(), StateW.begin(), StateW.end() );
推荐阅读
- machine-learning - 更改 Kmean 聚类的标签名称
- java - Java正则表达式将多行部分与子部分匹配
- javascript - JS 位移运算符 '>>' 没有返回正确的结果
- excel - 具有索引匹配的 Excel VBA
- flutter - 使用水平列表视图修复渲染框错误
- c# - 如何在字符串加入中添加换行符?
- javascript - EJS 变量未在 html 中定义
- sql - 如何在保留所有数据而不创建重复列的同时在部分重叠的键列上连接表?
- swift - 无法将“UnsafeMutableRawPointer”类型的值转换为预期的参数类型“UnsafePointer”
? - aws-sam - 一个本地模拟器上的多个 SAM 模板