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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:24:48+00:00 2026-06-10T23:24:48+00:00

title might be confusing, but lets say I have a template: template <typename T,

  • 0

title might be confusing, but lets say I have a template:

template <typename T, size_t offset>
struct offsetedIdxArray
{
//...
}

And after I create an instance:

static const size_t offset(1701);
offsetedIdxArray<zmq::socket_t, offset> oia;

Is there a way to get offset variable from oia. I know I can just use offset but from code style perspective i prefer to get it from oia if possible.

EDIT: I’m looking for a way to get offset without helper variable inside struct…

  • 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-10T23:24:50+00:00Added an answer on June 10, 2026 at 11:24 pm

    If you want to obtain the information from an offsetedIdxArray<T,N> object without adding any members to the class template, you can use a template function:

    #include <iostream>
    #include <cstddef>
    
    template <typename T, size_t offset>
    struct offsetedIdxArray
    {
    };
    
    template <typename T, size_t offset>
    size_t getOffset(const offsetedIdxArray<T, offset>&) {
      return offset;
    }
    
    int main()
    {
       offsetedIdxArray<int,5> oia;
       std::cout << getOffset(oia) << "\n";
    
    }
    

    Otherwise you can add a static constant or enum data member, as suggested in other posts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title might be confusing. Just say I have a newspaper article. I want
the title might be a little bit confusing, let me explain, ;) I have
the title might be too generic, but I have a very specific question about
Hi i know the Title might sound a little confusing but im reading in
The title of this question might be confusing but the problem is simple. I'm
I know the title might be confusing, but I'm not sure how to word
The title might be a little weird but let me explain. I have User,
the title might suggest it, but i'm looking for a way to have Facebooks
Title might be a bit confusing, so let me explain. I have a website
Okay, the post title might be a little confusing. I have this code: class

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.