Is delete *p an alternative to delete [] p?In what context one may need to dynamically allocate pointers to functions?What are the differences between a pointer variable and a reference variable in C++?PHP: Delete an element from an arrayDeleting array elements in JavaScript - delete vs spliceWhy is “using namespace std” considered bad practice?What is the “-->” operator in C++?What is the copy-and-swap idiom?Why are elementwise additions much faster in separate loops than in a combined loop?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?Why should I use a pointer rather than the object itself?

Multi tool use
Multi tool use

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

The use of multiple foreign keys on same column in SQL Server

Set-theoretical foundations of Mathematics with only bounded quantifiers

Can a German sentence have two subjects?

How do I create uniquely male characters?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

New order #4: World

What is the command to reset a PC without deleting any files

Why are only specific transaction types accepted into the mempool?

What would happen to a modern skyscraper if it rains micro blackholes?

Download, install and reboot computer at night if needed

How to report a triplet of septets in NMR tabulation?

A Journey Through Space and Time

What makes Graph invariants so useful/important?

TGV timetables / schedules?

Why is the design of haulage companies so “special”?

declaring a variable twice in IIFE

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Email Account under attack (really) - anything I can do?

Draw simple lines in Inkscape

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Is there a minimum number of transactions in a block?

Patience, young "Padovan"

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine



Is delete *p an alternative to delete [] p?


In what context one may need to dynamically allocate pointers to functions?What are the differences between a pointer variable and a reference variable in C++?PHP: Delete an element from an arrayDeleting array elements in JavaScript - delete vs spliceWhy is “using namespace std” considered bad practice?What is the “-->” operator in C++?What is the copy-and-swap idiom?Why are elementwise additions much faster in separate loops than in a combined loop?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?Why should I use a pointer rather than the object itself?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








14















The following code is from the Microsoft Documentation



int (**p) () = new (int (*[7]) ());
delete *p;


I think that delete [] p should be used here instead.



Is delete *p the same as delete [] p?










share|improve this question



















  • 5





    delete *p differs from delete [] p.

    – Jarod42
    Apr 4 at 20:10











  • You're right. They're not the same.

    – Cruz Jean
    Apr 4 at 20:10






  • 1





    typedef would make thing clearer.

    – Jarod42
    Apr 4 at 20:10












  • Anyway p[0] is not initialized. They have typo.

    – Jarod42
    Apr 4 at 20:14











  • delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

    – François Andrieux
    Apr 4 at 20:29


















14















The following code is from the Microsoft Documentation



int (**p) () = new (int (*[7]) ());
delete *p;


I think that delete [] p should be used here instead.



Is delete *p the same as delete [] p?










share|improve this question



















  • 5





    delete *p differs from delete [] p.

    – Jarod42
    Apr 4 at 20:10











  • You're right. They're not the same.

    – Cruz Jean
    Apr 4 at 20:10






  • 1





    typedef would make thing clearer.

    – Jarod42
    Apr 4 at 20:10












  • Anyway p[0] is not initialized. They have typo.

    – Jarod42
    Apr 4 at 20:14











  • delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

    – François Andrieux
    Apr 4 at 20:29














14












14








14


1






The following code is from the Microsoft Documentation



int (**p) () = new (int (*[7]) ());
delete *p;


I think that delete [] p should be used here instead.



Is delete *p the same as delete [] p?










share|improve this question
















The following code is from the Microsoft Documentation



int (**p) () = new (int (*[7]) ());
delete *p;


I think that delete [] p should be used here instead.



Is delete *p the same as delete [] p?







c++ arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 4 at 20:10









Guillaume Racicot

16.2k53872




16.2k53872










asked Apr 4 at 20:09









xiaokaoyxiaokaoy

7322719




7322719







  • 5





    delete *p differs from delete [] p.

    – Jarod42
    Apr 4 at 20:10











  • You're right. They're not the same.

    – Cruz Jean
    Apr 4 at 20:10






  • 1





    typedef would make thing clearer.

    – Jarod42
    Apr 4 at 20:10












  • Anyway p[0] is not initialized. They have typo.

    – Jarod42
    Apr 4 at 20:14











  • delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

    – François Andrieux
    Apr 4 at 20:29













  • 5





    delete *p differs from delete [] p.

    – Jarod42
    Apr 4 at 20:10











  • You're right. They're not the same.

    – Cruz Jean
    Apr 4 at 20:10






  • 1





    typedef would make thing clearer.

    – Jarod42
    Apr 4 at 20:10












  • Anyway p[0] is not initialized. They have typo.

    – Jarod42
    Apr 4 at 20:14











  • delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

    – François Andrieux
    Apr 4 at 20:29








5




5





delete *p differs from delete [] p.

– Jarod42
Apr 4 at 20:10





delete *p differs from delete [] p.

– Jarod42
Apr 4 at 20:10













You're right. They're not the same.

– Cruz Jean
Apr 4 at 20:10





You're right. They're not the same.

– Cruz Jean
Apr 4 at 20:10




1




1





typedef would make thing clearer.

– Jarod42
Apr 4 at 20:10






typedef would make thing clearer.

– Jarod42
Apr 4 at 20:10














Anyway p[0] is not initialized. They have typo.

– Jarod42
Apr 4 at 20:14





Anyway p[0] is not initialized. They have typo.

– Jarod42
Apr 4 at 20:14













delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

– François Andrieux
Apr 4 at 20:29






delete[] what was new[]ed and delete what was newed. Though in modern code you should avoid most uses of new, it's no longer the preferred way of dynamically creating objects. See std::make_unique and std::make_shared instead or use a standard container.

– François Andrieux
Apr 4 at 20:29













1 Answer
1






active

oldest

votes


















15














That code is invalid C++, because only pointers-to-objects can be deleted. *p has type int (*)(), which is a function pointer, not a pointer to an object.



Even MSVC itself does not compile it, even in permissive mode:



error C2541: 'delete': cannot delete objects that are not pointers


They should have used delete [] instead.






share|improve this answer

























  • In what context one may need to dynamically allocate pointers to functions?

    – Ayxan
    Apr 4 at 20:34











  • @Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

    – Acorn
    Apr 4 at 20:45











  • @Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

    – Acorn
    Apr 4 at 20:52






  • 1





    Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

    – txtechhelp
    Apr 4 at 22:04












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55524140%2fis-delete-p-an-alternative-to-delete-p%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









15














That code is invalid C++, because only pointers-to-objects can be deleted. *p has type int (*)(), which is a function pointer, not a pointer to an object.



Even MSVC itself does not compile it, even in permissive mode:



error C2541: 'delete': cannot delete objects that are not pointers


They should have used delete [] instead.






share|improve this answer

























  • In what context one may need to dynamically allocate pointers to functions?

    – Ayxan
    Apr 4 at 20:34











  • @Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

    – Acorn
    Apr 4 at 20:45











  • @Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

    – Acorn
    Apr 4 at 20:52






  • 1





    Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

    – txtechhelp
    Apr 4 at 22:04
















15














That code is invalid C++, because only pointers-to-objects can be deleted. *p has type int (*)(), which is a function pointer, not a pointer to an object.



Even MSVC itself does not compile it, even in permissive mode:



error C2541: 'delete': cannot delete objects that are not pointers


They should have used delete [] instead.






share|improve this answer

























  • In what context one may need to dynamically allocate pointers to functions?

    – Ayxan
    Apr 4 at 20:34











  • @Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

    – Acorn
    Apr 4 at 20:45











  • @Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

    – Acorn
    Apr 4 at 20:52






  • 1





    Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

    – txtechhelp
    Apr 4 at 22:04














15












15








15







That code is invalid C++, because only pointers-to-objects can be deleted. *p has type int (*)(), which is a function pointer, not a pointer to an object.



Even MSVC itself does not compile it, even in permissive mode:



error C2541: 'delete': cannot delete objects that are not pointers


They should have used delete [] instead.






share|improve this answer















That code is invalid C++, because only pointers-to-objects can be deleted. *p has type int (*)(), which is a function pointer, not a pointer to an object.



Even MSVC itself does not compile it, even in permissive mode:



error C2541: 'delete': cannot delete objects that are not pointers


They should have used delete [] instead.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 4 at 20:22

























answered Apr 4 at 20:17









AcornAcorn

6,33611441




6,33611441












  • In what context one may need to dynamically allocate pointers to functions?

    – Ayxan
    Apr 4 at 20:34











  • @Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

    – Acorn
    Apr 4 at 20:45











  • @Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

    – Acorn
    Apr 4 at 20:52






  • 1





    Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

    – txtechhelp
    Apr 4 at 22:04


















  • In what context one may need to dynamically allocate pointers to functions?

    – Ayxan
    Apr 4 at 20:34











  • @Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

    – Acorn
    Apr 4 at 20:45











  • @Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

    – Acorn
    Apr 4 at 20:52






  • 1





    Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

    – txtechhelp
    Apr 4 at 22:04

















In what context one may need to dynamically allocate pointers to functions?

– Ayxan
Apr 4 at 20:34





In what context one may need to dynamically allocate pointers to functions?

– Ayxan
Apr 4 at 20:34













@Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

– Acorn
Apr 4 at 20:45





@Ayxan That would be another question, but for instance you may want to have a list of arbitrary operations to execute.

– Acorn
Apr 4 at 20:45













@Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

– Acorn
Apr 4 at 20:52





@Ayxan I have quickly posted it here: stackoverflow.com/q/55524710/9305398

– Acorn
Apr 4 at 20:52




1




1





Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

– txtechhelp
Apr 4 at 22:04






Even though this is specific to MSVC, g++ gives the following similar error when trying to compile: error: cannot delete expression of type 'int (*)()' .. seems odd that MS would have missed something that simple in their docs :/

– txtechhelp
Apr 4 at 22:04




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55524140%2fis-delete-p-an-alternative-to-delete-p%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







ZXO 1urlY,0DxNO9NIDqq76Izd58fG5Xaz8fc,h56h4nu1 NTpjcuY
SST mMpmZ FY,Gl SoMspmluaof0,wFo3P

Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

NetworkManager fails with “Could not find source connection”Trouble connecting to VPN using network-manager, while command line worksHow can I be notified about state changes to a VPN adapterBacktrack 5 R3 - Refuses to connect to VPNFeed all traffic through OpenVPN for a specific network namespace onlyRun daemon on startup in Debian once openvpn connection establishedpfsense tcp connection between openvpn and lan is brokenInternet connection problem with web browsers onlyWhy does NetworkManager explicitly support tun/tap devices?Browser issues with VPNTwo IP addresses assigned to the same network card - OpenVPN issues?Cannot connect to WiFi with nmcli, although secrets are provided

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.