为什么我的std :: vector没有任何元素?

时间:2019-05-30 19:49:53

标签: c++

我有一个std :: vector [int]类型的成员向量,并且在传感器类中名为 IndicesOfProvidersForReplicas

通过push_back插入一些值时,向量保持为空,如最后一行或调试器所示。为什么?

    int index = providerInfo.getProvider()->getIndex();
    sensor.getIndicesOfProvidersForReplicas().push_back(index);
    sensor.getIndicesOfProvidersForReplicas().push_back(2);
    std::cout << sensor.getIndicesOfProvidersForReplicas().size();

SensorInformation.h:

class SensorInformation {
public:
    ...
    std::vector<int> getIndicesOfProvidersForReplicas() const;
    void setIndicesOfProvidersForReplicas(std::vector<int> indicesOfProvidersForReplicas);

private:
    ...
    std::vector<int> indicesOfProvidersForReplicas;

SensorInformation.cc:

std::vector<int> SensorInformation::getIndicesOfProvidersForReplicas() const {
    return indicesOfProvidersForReplicas;
}

void SensorInformation::setIndicesOfProvidersForReplicas(std::vector<int> indicesOfProvidersForReplicas) {
    this->indicesOfProvidersForReplicas = indicesOfProvidersForReplicas;
}

如果需要查看更多代码,请发表评论。

0 个答案:

没有答案