C++ C++;:从向量中获取值

C++ C++;:从向量中获取值,c++,vector,C++,Vector,我有一个函数,我传递一个指向无符号字符向量的指针 有人能告诉我如何获取函数中的一个值吗 double CApp::GetCost(unsigned char *uBytes) { unsigned char iHP; iHP=uBytes[49]; //this does not work } 编辑: 对不起,我最初认为我应该简化我的代码,但我认为太多可能会出错。下面是真正的宣言: // --------------------------------------- struct

我有一个函数,我传递一个指向无符号字符向量的指针

有人能告诉我如何获取函数中的一个值吗

double CApp::GetCost(unsigned char *uBytes)
{
   unsigned char iHP;
   iHP=uBytes[49]; //this does not work
}
编辑: 对不起,我最初认为我应该简化我的代码,但我认为太多可能会出错。下面是真正的宣言:

// ---------------------------------------
struct ByteFeature
{
    unsigned char Features[52];
};

class clsByteFeatures : public CBaseStructure
{
private:
   vector<ByteFeature> m_content;

protected:
   virtual void ProcessTxtLine(string line);

public:
   vector<ByteFeature> &Content();
   void Add(ByteFeature &bf);
};

vector<ByteFeature> &clsByteFeatures::Content()
{
   return m_content;
}
另一个问题: 像这样简单地传递向量会不好吗

double CApp::GetCost(vector<unsigned char> &uBytes)
{
  //...
}
double CApp::GetCost(向量和单位)
{
//...
}
编辑:

在您发布新帖子之后,我觉得您只需要返回对m_内容元素的引用,然后将引用传递给
GetCost
函数

ByteFeature& clsByteFeatures::operator[](int i) { return m_content.at(i); }


double GetCost(const ByteFeature& bf)
{
    std::cout << bf.Features[49]; << std::endl;
    return 0.0;
}

这是正确的语法。为什么是“当然”?第二种方法比第一种好。另外,如果您不打算修改向量,请按ref传递它
const
,先生。我现在记得为什么我选择了指针而不是向量。结构MyBytes{无符号字符MyByteValues[52];};我想,我不能将其作为向量传递,所以我需要使用指针。我猜m_ByteFeatures是clsByteFeatures的实例?
Would it be bad to simply pass the vector like this?
double CApp::GetCost(vector<unsigned char> &uBytes)
double CApp::GetCost(const vector<unsigned char> &uBytes)
{
   try
   {
     unsigned char iHP = uBytes.at(49);
     //... 
   }
   catch(std::exception& e)
   {
     // process e
   }
   //...
}
ByteFeature& clsByteFeatures::operator[](int i) { return m_content.at(i); }


double GetCost(const ByteFeature& bf)
{
    std::cout << bf.Features[49]; << std::endl;
    return 0.0;
}
GetCost(m_ByteFeatures[iUnitID]);