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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:50:38+00:00 2026-06-06T13:50:38+00:00

I try to reference to an child element of an global variable by using

  • 0

I try to reference to an child element of an global variable by using an template parameter – it does work for globals but not for childs of globals – why is the position resolving of an child not possible at compile-time?

typedef unsigned char byte_t;
typedef unsigned short word_t;

struct byte_reg_t
{
     byte_t low;
     byte_t high;
};

union word_reg_t
{
     word_t value;
     byte_reg_t part;
};

word_t rax;
byte_t rah;
word_reg_t r16;
byte_reg_t r8;

template<typename ValueType, ValueType& Ref>
ValueType ret_ref()
{
     return Ref;
}

int main()
{
    word_t x = ret_ref<word_t,rax>();
    byte_t h = ret_ref<byte_t,rah>();
    //word_t sx = ret_ref<word_t,r16.value>(); // compile error
    //byte_t sh = ret_ref<byte_t,r16.part.low>(); // compile error
    //byte_t sh2 = ret_ref<byte_t,r8.low>(); // compile error

    return 0;
} 

the VS2010 and clang 3.1 compiler does not allow the // compile error lines

thx for any clear description because i don’t see any technical reason for that behavior of the compilers

  • 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-06T13:50:41+00:00Added an answer on June 6, 2026 at 1:50 pm

    The answer lies in the C++ Standard. Sorry for being outdated, but my version (ISO/IEC 14882, 2nd Ed. 2003) says (page 246):

    §14.3.2 Template non-type arguments

       [..]
    

    3 [Note: Addresses of array elements and names or
    addresses of non-static class members are not acceptable template-arguments.[..]]

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

Sidebar

Related Questions

if in a literal object i try to reference a function using this inside
I receiving a undefined reference error when try to compile an c++ program. I'm
I try to use the boolean in my class and get this message reference
I'm working on a program where I try to pass parameters by reference. I'm
Try to see which cast is faster (not necessary better): new c++ case or
i use mysql work bench to export sql from erd that i create, but
Let's say I have a parent/child-relationship ob objects and try to create a parent
Whenever I try to remove an object/child with enterframe running I always get null
In phpMyAdmin when i try to add foreign key some error occurs and does
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals

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.