1

I looked around the web for this but I did not find an answer. If my class has a protected member declared as such: char * arr[3] = {"Blah", "Blah", "Blah"} Would I need to delete this member in the destructor? If so, what is the correct syntax? Thank you!

7
  • 4
    You only need to delete if you use new. So no. This is an array literal that can be stored on the stack. Commented Oct 25, 2017 at 22:39
  • @PaulRooney what is a way that I could declare this method as dynamic? Would it be char ** arr = new char*[3]; ? Commented Oct 25, 2017 at 22:42
  • Use std::string for strings. Your compiler should complain about a missing const. Commented Oct 25, 2017 at 23:05
  • 1
    @manni66 I can’t use the string class, it’s a programming assignment and they want all strings to be stored as char* Commented Oct 25, 2017 at 23:06
  • 1
    A pointer to a string constant has to be const char*. Commented Oct 25, 2017 at 23:09

1 Answer 1

1

Would I need to delete this member in the destructor?

No.

And of course:

I can’t use the string class, it’s a programming assignment and they want all strings to be stored as char*

This is a quite silly restriction in a C++ assignment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.