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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:12:20+00:00 2026-05-30T16:12:20+00:00

This Code returns an error on the delete [] placard_; call void Protestor::destroy() {

  • 0

This Code returns an error on the delete [] placard_; call

void Protestor::destroy() { //Free's caller Protestor's dynamic memory
    delete [] placard_;
}

This code does not.

void Protestor::destroy() { //Free's caller Protestor's dynamic memory
    delete placard_;
}

This goes against my class notes, which state to ALWAYS call

delete []

rather than

delete

What is the explanation for this behaviour? Under what conditions must ‘delete’ be called instead of ‘delete []’?

Here is the Definition for the Protester and Sign classes.

class Protester
{
  public:
    Protester(string name, string signSlogan, int signHeight, int signWidth,
              int rcmp_file = 0 );
    string getName() const;
    Sign getPlacard() const;
    void changePlacard( string newSlogan, int newHeight, int newWidth);
    void setRCMPfile(int RCMP_file);
    int getRCMPfile() const;

    //Big Three
    Protester(const Protester& other); //Copy Constructor
    ~Protester(); //Destructor
    Protester& operator= (const Protester& other); //Assignment Constructor


private:
    // name of the Protester
    string name_;

    // a sign the protester is wielding
    Sign* placard_;

    // the RCMP file number tracking this person (zero means no RCMP report)
    int rcmp_file_;

    //Big Three Helper Functions
    void copy(const Protester& other); //Performs Deep Copy of const Protester&
    void destroy(); //deletes [] placard_
                    //sounds better then cleanup, in my humblest of opinions.
};

class Sign
// a class representing information about signs/placards
{
public:
    // constructor to initialize sign text and dimensions
    Sign(string statement, int height, int width);

    // return sign text
    string getStatement() const;

    //return sign height
    int getHeight() const;

    //return sign width
    int getWidth() const;

    // change sign text
    void setStatement(string statement);

    // change sign dimensions
    void setSize(int height, int width);

private:
    // the text of the sign
    string statement_;

    // dimensions of the sign
    int height_;
    int width_;
};
  • 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-30T16:12:21+00:00Added an answer on May 30, 2026 at 4:12 pm

    This goes against my class notes, which state to ALWAYS call delete [] rather than delete

    No that’s wrong. You have to pair calls to new and delete and calls to new[] and delete[].

    Note:
    But that’s not how you should to that in modern C++. Use std::shared_ptr or std::unique_ptr instead. This is usually a much safer choice. Calls to new/new[] should be nearly always enclosed in smart pointer and delete should not be needed at all. Very few exceptions.

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

Sidebar

Related Questions

This code returns an error: AttributeError: can't set attribute This is really a pity
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
Basically this code below returns the right information, but I need to add the
Can anyone explain why this code with the given routes returns the first route?
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
Visual Studio C++ 2008 I am using this code. However, gethostbyname always returns an
as all you know $(#ID) returns the element having ID. but this code always
In this C# code snippet, DateTime.Now.Month.ToString() returns 7 as output. I would like to
If I have code like this: string s = MyClass.GetString(); // Returns string containing
In my test, I do this: delete :destroy, :id => p.id assert_equal You do

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.