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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:41:25+00:00 2026-05-11T01:41:25+00:00

In C++ the following code gives a compiler error: void destruct1 (int * item)

  • 0

In C++ the following code gives a compiler error:

void destruct1 (int * item) {   item->~int(); } 

This code is nearly the same, I just typedef the int to another type and something magic happens:

typedef int myint;  void destruct2 (myint * item) {   item->~myint(); } 

Why does the second code work? Does an int get a destructor just because it has been typedefed?

In case you wonder why one ever would like to do this: This comes from refactoring C++ code. We’re removing the standard heap and replacing it with selfmade pools. This requires us to call placement-new and the destructors. I know that calling destructors for primitive types is useless, but we want them in the code nevertheless in case we later replace PODs with real classes.

Finding out that naked int’s don’t work but typedefed ones do was quite a surprise.

Btw – I have a solution that involves template-functions. We just typedef inside the template and everything is fine.

  • 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. 2026-05-11T01:41:26+00:00Added an answer on May 11, 2026 at 1:41 am

    It’s the reason that makes your code work for generic parameters. Consider a container C:

    template<typename T> struct C {     // ...     ~C() {         for(size_t i = 0; i<elements; i++)             buffer[i].~T();     } }; 

    It would be annoying to introduce special cases for built-in types. So C++ allows you to do the above, even if T happens to equal to int. The holy Standard says in 12.4 p15:

    The notation for explicit call of a destructor can be used for any scalar type name. Allowing this makes it possible to write code without having to know if a destructor exists for a given type.

    The difference between using a plain int and a typedef’ed int is that they are syntactically different things. The rule is, that in a destructor call, the thing after the ~ is a type-name. int is not such a thing, but a typedef-name is. Look it up in 7.1.5.2.

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

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Developer Library - Introduction to Cocoa Scripting Guide May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer Consider what you get when you add a number to… May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer Try the RESTful API from ISBN DB http://isbndb.com/api/v2/docs May 13, 2026 at 5:50 pm

Related Questions

I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles
I'm using boost::python to embed some python code into an app. I was able
I'm reading from a binary data file which is written by invoking the following
I have recently discovered that when I have pointers within a class, I need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.