Question from the C++ test

Write a C++ constructor that takes a char pointer and copies the string into a new char array.

Medium

Consider the following code:

class Test
{
    private:
        char *str;
    public:
        Test(char *s1)
        {
            ….
        }
        ~Test()
        {
            delete[] str;
        }
}

void main()
{
    Test s(“test string”);
}

What is the correct definition of constructor Test, in order to ensure that code runs successfully?

Author: W3D TeamStatus: Published(Update)Question passed 80 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!