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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:36:49+00:00 2026-05-18T09:36:49+00:00

I need some samples of bad C++ code that will illustrate violation of good

  • 0

I need some samples of bad C++ code that will illustrate violation of good practices. I wanted to come up with my own examples, but I am having a hard time coming up with examples that are not contrived, and where a trap is not immediately obvious (it’s harder than it seems).

Examples would be something like:

  1. Not defining copy constructor for classes with std::auto_ptr members, and using std::auto_ptr members with forward-declared classes.
  2. Calling virtual functions from a constructor or a destructor (directly or indirectly).
  3. Overloading a template function.
  4. Circular references with boost::shared_ptr.
  5. Slicing.
  6. Throwing exceptions from C callbacks (directly or indirectly).
  7. Floating point comparison for equality.
  8. Exception safety of constructors with raw pointer members.
  9. Throwing from destructors.
  10. Integer overflow when compiled on different architectures (mismatch of size_t and int).
  11. Invalidating a container iterator.

…or any other evil thing you can think of.

I’d appreciate some pointers to existing resources, or a sample or two.

  • 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-18T09:36:50+00:00Added an answer on May 18, 2026 at 9:36 am

    The most vexing parse is an amazingly counterintuitive result of the way C++ parses things like this:

    // Declares a function called "myVector" that returns a std::vector<float>.
    std::vector<float> myVector(); 
    // Does NOT declare an instance of std::vector<float> called "myVector"
    
    // Declares a function called "foo" that returns a Foo and accepts an unnamed
    // parameter of type Bar.
    Foo foo(Bar()); 
    // Does NOT create an instance of Foo called "foo" nor creates a Bar temporary
    
    // Declares a function called "myVector" that takes two parameters, the first named
    // "str" and the second unnamed, both of type std::istream_iterator<int>.
    std::vector<float> myVector( 
        std::istream_iterator<int>(str),
        std::istream_iterator<int>()
    );
    // Does NOT create an instance of `std::vector<float>` named "myVector" while copying
    // in elements from a range of iterators
    

    This will surprise just about anybody who is not familiar with this particular quirk of the language (myself included when I started learning C++).

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

Sidebar

Related Questions

I need some asp.net pagination code samples. I would like suggestions on open source
I need some code samples (and I also really curious about them) of Scala
I would like to understand how socket work, especially I need some code samples
I need some samples / source code for a background subtraction algorithm for using
I need your help with some sample code for a situation I could not
I need your help in JAVA (with some sample code if possible) regarding to
Need some regular expressions help. So far I have my code working to allow
I'm reformatting some really bad HTML using jQuery. I need to splice sibling <font>
I have a samples of some documents in .doc format. So I need to
I need some tutorials or samples which cover the following topics, does anyone have

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.