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

  • Home
  • SEARCH
  • 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 7667399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:05:34+00:00 2026-05-31T15:05:34+00:00

I came across this code and was wondering what it means. But even after

  • 0

I came across this code and was wondering what it means.
But even after some 15 minutes of looking at it does not make sense to me.

template< typename T >
struct Vector4 {
    typedef T Vector4<T>::* const vec[4];
    static const vec constVec;

    //just to have some member instances of T
    T member1, member2, member3, member4;
};

So what is the type of constVec?
Please do not just repeat the typedef but explain in common language.

My notes so far:

  • Why are there two types (T and Vector4<T>), is this a function pointer?
  • What does ::* mean? Take everything from the scope of Vector4?
  • Is it a const pointer array? But why the :: then?
  • 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-05-31T15:05:36+00:00Added an answer on May 31, 2026 at 3:05 pm

    constVec is an array of 4 constant pointers to the members of the Vector4<T> class which are of type T

    Note: The members aren’t constant, the pointers themselves are.

    First, since these are constant pointers, you need to initialize them in the constructor: (I’ve just noticed the static qualifier, so it has to be initialized outside the class, but if it weren’t static, you’d need to do that in the initialization list.)

    template< typename T >
    struct Vector4 {
        typedef T Vector4<T>::* const vec[4];
        static const vec constVec;
    
        //just to have some member instances of T
        T member1, member2, member3, member4;
    
    };
    
    template<typename T>
    const typename Vector4<T>::vec Vector4<T>::constVec = {&Vector4::member1,&Vector4::member2,&Vector4::member3,&Vector4::member4};
    
    int main() {
        Vector4<int> v;
        for(int i=0; i<4; i++) {
            (v.*Vector4<int>::constVec[i]) = 5;
        }
    return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just came across this. It's not affecting anything really but i'm wondering why it's
I came across this piece of code and am wondering what it means: typ,
I recently came across this in some code - basically someone trying to create
i came across this problem, my code in the viewWillAppear method is not executed
I was browsing some code and I came across this macro definition #define D(x)
I am dissecting some code and came across this, $sql = 'SELECT page.*, author.name
I came across this code just few minutes back here in Stack Overflow. I
While writing some code i came across this issue: #include <iostream> class random {
just wondering if someone else came across this. I got this piece of code
I realise this code is faulty. However, I came across some curious behaviour which

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.