Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:55:48+00:00 2026-06-17T14:55:48+00:00

I have a function that I pass a pointer to a vector of unsigned

  • 0

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)
{
  //...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:55:50+00:00Added an answer on June 17, 2026 at 2:55 pm
    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 uBytes to be modified.

    double CApp::GetCost(const vector<unsigned char> &uBytes)
    {
       try
       {
         unsigned char iHP = uBytes.at(49);
         //... 
       }
       catch(std::exception& e)
       {
         // process e
       }
       //...
    }
    

    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 GetCost function

    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;
    }
    

    then you call:

    GetCost(m_ByteFeatures[iUnitID]); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a function pointer that can take various types of parameters.
I have a function that i want to pass as a parameter function myFun(){
I have a function that I want to pass an argument, market, to the
I have a pretty large object that I need to pass to a function
I have a function that returns two values in a list. Both values need
I have an LLVM (version 2.7) module with a function that takes a pointer
I have a function that takes a pointer as a reference argument, but I
I have a function that takes a pointer to a superclass and performs operations
Say I have a function that takes a const reference to a pointer... Example:
I have a function that I pass an array into and an int into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.