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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:34:23+00:00 2026-06-06T09:34:23+00:00

I have typedef std::string OrderID; I would like to overload the operator ++ for

  • 0

I have

typedef std::string OrderID;

I would like to overload the operator ++ for this. The value of OrderID starts out at 1 and is just incremented using hex every time. Possible values are…

001

002

…

00A

00B

…

00F

010

…

1) Can you overload operators for specific type defines, so that std::string++ is not overloaded?

2) Can you increment like above (using Hex)?

Thanks

  • 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-06T09:34:26+00:00Added an answer on June 6, 2026 at 9:34 am

    If you define

    OrderID& operator++(OrderID& x)
    {
         //...
    }
    

    it will apply to std::string as well.

    You should use composition instead.

    You should use a free function that does that, not necessarily on your defined type. It could also manipulate a string, and that’s fine.

    void incrementString(OrderID& x)
    {
      //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like this: class MapIndex { private: typedef std::map<std::string, MapIndex*> Container; Container
If I have an object like this: struct Bar { std::string const& property(); };
This is kind of last resort.. So I have two maps. typedef std::map <string,
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
so i have a flyweight of strings type: typedef boost::flyweight< std::string, boost::flyweights::intermodule_holder > SymbolName_t;
I have two vectors typedef std::vector<std::string> messages; typedef std::vector<std::string> addMessage; messages st; addMessage additionlMsgs;
I have the following code: #include <string> #include <iostream> #include <tr1/unordered_map> typedef std::tr1::unordered_map<unsigned long
I have a map named valueMap as follows: typedef std::map<std::string, std::string>MAP; MAP valueMap; ...
So I have such function: boost::shared_ptr<my_class> get_class_by_name(std::string name) { typedef std::map<boost::shared_ptr<my_class>, my_description> map_t; BOOST_FOREACH(map_t::value_type
I have class with member functions: typedef std::function<bool (const std::string &)> InsertFunction; bool insertSourceFile(

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.