I have a function that I pass a pointer to a vector of unsigned char.
Can somebody please tell me how to get one of the values inside the function?
double CApp::GetCost(unsigned char *uBytes)
{
unsigned char iHP;
iHP=uBytes[49]; //this does not work
}
Edit:
Sorry, I first thought that I should simplify my code, but I think too much can go wrong. Now here is the real declaration:
// ---------------------------------------
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;
}
And this is how I use it:
dblTargetCost = GetCost(m_ByteFeatures.Content()[iUnitID].Features);
Another question:
Would it be bad to simply pass the vector like this?
double CApp::GetCost(vector<unsigned char> &uBytes)
{
//...
}
Not it’s the better way to pass it by reference. however you may want to add const qualifier if you don’t want
uBytesto be modified.EDIT:
After you new post, I feel you only need to return a reference to the element of m_content then pass the reference to
GetCostfunctionthen you call: