Question from the C++ test

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

Archived

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: Abha AgrawaStatus: Archived(New question!)Question passed 426 times
0
Community EvaluationsNo one has reviewed this question yet, be the first!