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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:22:15+00:00 2026-05-18T08:22:15+00:00

I am implementing a smart pointer class using generics and I wanted to force

  • 0

I am implementing a smart pointer class using generics and I wanted to force users of this class to properly construct the smart pointer using syntax such as

 MyReference<TestCls>(mytest3))

or

MyReference<TestCls> mytest4(new TestCls());

so I have used the explicit keyword on the CTOR, to prevent this:

MyReference aRef = NULL;

However due to unfortunate circumstances beyond my control, I am working on code that is compiled using the ancient MSVC++ 4.1 compiler. I get the following errors when I include the explicit keyword:

MyReference.h(49) : error C2501: ‘explicit’ : missing decl-specifiers
MyReference.h(51) : error C2143: syntax error : missing ‘;’ before ”
MyReference.h(52) : error C2238: unexpected token(s) preceding ‘:’
MyReference.h(52) : error C2059: syntax error : ‘int constant’

When I add a #define explicit those errors disappear.
This was a hack on my part, just to get the compiler to ignore the keyword. I’m guessing that this means that explicit is not supported by yon olde compiler.
Can someone confirm this and is there anyone out there with knowledge of a workaround solution for this?

Merci Beaucoups,
Dennis.

  • 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-18T08:22:16+00:00Added an answer on May 18, 2026 at 8:22 am

    This site has a workaround for this, namely:

    Unfortunately, older compilers may not
    support the use of “explicit”, which
    could be a headache. If you’re stuck
    working with an out-of-date compiler
    and can’t get one that has better
    support for the C++ standard, your
    best solution may be to take advantage
    of the fact that only a single
    implicit conversion will take place
    for a given value. You can exploit
    this by using an intermediate class
    that implicitly creates an object of
    each type, and then have your main
    class implicitly create objects from
    that class:

    class proxy
    {
        public:
        proxy(int x) : x(x) {} ;
        getValue() { return x; }
    
        private:
        int x;
    
    };
    
    class String
    {
        // this will be equivalent of explicit
        String(proxy x) { /* create a string using x.getValue(); */ }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

implementing publishActivity in PHP using the REST API using this code: $activity = array(
While implementing a design using nested generic collections, I stumbled across those limitations apparently
Right now, I am implementing this with a split, slice, and implosion: $exploded =
I am implementing a web application that has many users and I would give
Resharper automatically moves to the newly created class, method etc, when creating it using
Can someone point me to a good tutorial for implementing Excel Smart Tags in
I'm creating a smart client application using .NET 3.5. A Winforms client connecting through
I was wondering if it is possible to create a smart pointer baseclass without
I am looking for good practices for implementing a smart architecture and way to
I am going to start implementing some unit tests for a codebase that is

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.