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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:48:50+00:00 2026-05-31T20:48:50+00:00

Im writing some helper functions for a project im working on. I’ve always wanted

  • 0

Im writing some helper functions for a project im working on. I’ve always wanted a typeof operator. I know it doesn’t exist in my current IDE (visual studio ’10), so im trying to write an implementation for it. It should work something like this:

auto var = new typeof(<expression>);

It should just be a compile-time retrievable type based off the expression and should be possible. C++ uses this when inducing template arguments, for instance:

template< typename A >
void foo(A unused) { 
/*  can be invoked like foo(5) with A = int     */
    typedef A type;
    type * used = new type;
}

So i thought i could play around with macroes, classes and templates.. something like this:

#define typeof(expression)  (_type_creater().inducer(expression)::type)

template<typename T>
class _type_holder{
public:
    typedef T type;
};

class _type_creater{
public:
template< class B >
    _type_holder<B> inducer(B _temp) {
        /*  Here compiler induces the templated expression and creates a typename out of it.
            this we can use extract typename from _type_holder, except a instantiatet type apparantly
            doesn't have access to typedef'd typenames.
        */
        return _type_holder<B>();
    }
};

So the problem is basically, that this is illegal:

struct a
{
   typedef int type;
}
...
a mya;
new mya::type; //or mya.type

So the first question is, why is this illegal? Why can’t you retrieve typenames from instantiatet types?
Second question, can i do this at all? I tried looking a boosts TYPEOF, but couldn’t make much sense of it, and it seems it just utilizes bugs in VC compilers (“//VC7.0 specific bugfeature”, “//VC8.0 specific bugfeature”, “// This uses nice VC6.5 and VC7.1 bugfeature”).
Am i out of luck?

  • 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-31T20:48:51+00:00Added an answer on May 31, 2026 at 8:48 pm

    An object is not a scope. The scope resolution operator (::) is only applicable to scopes (class scope, namespace scope, global (namespace) scope). I gave a bit of additional information as a theory in a comment on the question.

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

Sidebar

Related Questions

I'm writing some helper functions that take a SqlDataReader and process the results. Now
I'm contemplating writing some helper functions to make it easier to do simple changes
I have been writing some helper functions in Android 3.0's renderscript, and have come
I'm currently writing some general purpose .net libraries that contain usual helper classes. For
I'm writing some custom helpers the current one involves a sort of datagrid control
I have a browser helper object on IE that have some clipboard history functions.
I'm in the process of writing a simple prototype in Node.js with some helper
I'm writing some folding functions and I am at a point where I need
I have some PowerShell helper functions in a file. I'd like to make them
I've been writing some declarative Razor Helpers (using the @helper syntax) for use with

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.