I have a problem when I derive a String class from std::string and I test it.
Here is the String class:
namespace Types
{
class String : public std::string
{
public:
String();
/*!
* @fn String(const String &other);
* @brief Copy contructor
* @param other
*/
String(const String &other)
: std::string(other) {}
String(const char* format_string, ...);
virtual ~String();
};
} /* namespace Types */
And here is the test class :
class String_test : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(String_test);
CPPUNIT_TEST(testCopyConstructor);
CPPUNIT_TEST_SUITE_END();
public:
void setUp(void)
{
mTestObj = new Types::String();
}
void tearDown(void)
{
delete mTestObj;
}
protected:
void testCopyConstructor(void)
{
*mTestObj = "toto";
std::cout << *mTestObj << std::endl;
Types::String new_string((const Types::String&)mTestObj);
CPPUNIT_ASSERT(true == true);
}
private:
Types::String *mTestObj;
};
The compilation is ok but when the program is running I have this error:
##Failure Location unknown## : Error
Test name: String_test::testCopyConstructor
uncaught exception of type std::exception (or derived).
- basic_string::_M_construct null not valid
I have searched the documentation about copy constructor and derived class, it seems that is ok in code. I don't understand what's the problem.
Anyone have an idea ?
Thanks