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 8277291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:38:54+00:00 2026-06-08T08:38:54+00:00

I need to access a vector pointer elements, I have the following code for

  • 0

I need to access a vector pointer elements, I have the following code for my animation structures (simplified here, unnecessary variables cut off):

struct framestruct {
    int w,h;
};
struct animstruct {
    vector<framestruct> *frames;
};

vector<framestruct> some_animation; // this will be initialized with some frames data elsewhere.

animstruct test; // in this struct we save the pointer to those frames.

void init_anim(){
    test.frames = (vector<framestruct> *)&some_animation; // take pointer.
}

void test_anim(){
    test.frames[0].w; // error C2039: 'w' : is not a member of 'std::vector<_Ty>'
}

The array works, I tested it by:
test.frames->size() and it was 7 as I planned.

So how can I access the vector elements (w and h) at N’th index from the vector?

  • 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-08T08:38:58+00:00Added an answer on June 8, 2026 at 8:38 am

    You need to dererference the pointer before accessing the array. Just like you are doing with the -> operator to get the size.

    (*test.frames)[0].w;
    

    You could use the -> operator to also access the [] operator method, but the syntax isn’t as nice:

    test.frames->operator[](0).w;
    

    If you want to be able to use [] directly like a true vector syntactically, then you can either allow the frames member to take a copy of the vector, you it can reference the vector. Or, you can overload [] on the animstruct itself to use the [] syntax on your test variable.

    Copy:

    struct animstruct { vector<framestruct> frames; };
    animstruct test;
    void init_anim(){ test.frames = some_animation; }
    
    test.frames[0].w;
    

    Reference:

    struct animstruct { vector<framestruct> &frames;
                        animstruct (vector<framestruct> &f) : frames(f) {} };
    animstruct test(some_animation);
    void init_anim(){}
    
    test.frames[0].w;
    

    Overload:

    struct animstruct { vector<framestruct> *frames;
                        framestruct & operator[] (int i) { return (*frames)[i]; } };
    animstruct test;
    void init_anim(){ test.frames = &some_animation; }
    
    test[0].w;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need access to the uint64_t typedef from stdint.h in some wrapper code that
I have two different modules that need access to a single file (One will
i need to access folder in project .I have used Directory.CurrentDirectory and it is
I have a vector< Object > myvec which I use in my code to
I need to access the contents of a vector. The vector contains a structure
I need to set up and access a two dimensional vector of structure in
I would like to have a vector z, and be able to access it
I need to access two values in a vector called camerapos which contains the
I have this code to represent bank: class Bank { friend class InvestmentMethod; std::vector<BaseBankAccount*>
I've got an app running maximized in a borderless window and need access to

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.