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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:54+00:00 2026-05-25T18:58:54+00:00

Will the following give a compilation error? delete cout; delete cin; The answer is

  • 0

Will the following give a compilation error?

delete cout;
delete cin;

The answer is : No.

It is a flaw in the implementation of stream classes from the Standard library. They have the following conversion function to void* type, which means, all stream objects can be implicitly converted to void*:

operator void * ( ) const;

This is very useful in general as it lets us write very idiomatic loop, say, when reading input from files. But at the same time, it lets user to write delete stream. As I said, you can delete any stream object. So all of these are allowed:

delete ss;  //declare std::stringstream ss;
delete iss; //declare std::istringstream iss;
delete oss; //declare std::ostringstream oss;

Only that they’ll give a warning, saying (see at ideone):

warning: deleting ‘void*’ is undefined

which you can easily avoid just by casting, say, tochar*. But the program has still issue, and most likely will crash when running it.

—

So my question is, has this issue been addressed and fixed, in C++11? The following article provides one fix for this problem:

  • The Safe Bool Idiom

—

Edit:

From @Xeo’s comment on @Alf’s answer:

  • Is the safe-bool idiom obsolete in C++11?

The paper which proposed a fix for this issue:

  • Explicit Conversion Operator
    Draft Working Paper
    Revision 1
  • 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-25T18:58:55+00:00Added an answer on May 25, 2026 at 6:58 pm

    It has apparently been fixed.

    At least, in N3290 you have std::basic_ios::operator bool instead of that void* conversion, and this operator bool is declared explicit.

    Note that C++98/C++03 did not support explicit type conversion operators, but C++11 does.

    An explicit type conversion operator

    N3290 §12.3.2/2;
    is only considered as a user-defined conversion
    for direct-initialization (8.5)

    And that might seem to be impractical for the condition in e.g. a while or for statement.

    Happily,

    N3290 §4/3;
    An expression e can be implicitly converted to a type T if and only if the declaration T t=e; is well-formed, for some invented temporary variable t (8.5). Certain language constructs require that an expression be converted to a Boolean value.
    An expression e appearing in such a context is said to be contextually converted to bool and is well-formed if and only if the declaration bool t(e); is well-formed, for some invented temporary variable t (8.5). The effect of either implicit conversion is the same as performing the
    declaration and initialization and then using the temporary variable as the result of the conversion.

    where bool t(e); is a direct-initialization.

    E.g. you don’t have to explicit convert a stream object used as condition in a while, because there is implicitly an explicit conversion (he he).

    Unfortunately, searching N3290 I can’t find any list of the “certain language constructs” where this happens, but in comments to this answer JohannesD wrote:

    Searched through the FDIS for “contextually”, and the whole list seems to be: if, while,
    do, for, noexcept, and static_assert conditions; the first operand of ?:; both
    operands of && and ||; and the operand of !.

    Cheers & hth.,

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

Sidebar

Related Questions

I need a regex that will give me the following results from each example
Something like the following will not give me a compile-time or runtime error and
On this coderanch link, I found that the following comment will give compiler error
The following code will give a hard fail when run under Windows 7 32bit:
I presume that the following will give me 10 volatile ints volatile int foo[10];
Will the following code result in a deadlock using C# on .NET? class MyClass
Will the following query evaluate to true (1), false (0), or NULL? SELECT '%'
Will the following append() in the catch cause the rethrown exception to see the
Will the following program cause any problem during compiling and execution process? class A{
The following will cause infinite recursion on the == operator overload method Foo foo1

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.