|
-
June 22nd, 2009, 10:04 AM
#1
Constructor to extend existing class
I would like to extend the ANSI string class to include rudimentary split and join functions. I am NOT adding any new data fields to string:
class string_sj : public string {
public:
...
}
I would like to be able to use constructs such as
void arbitrary_function(string & s)
{
string_sj myString = s;
// or
string_sj *pMyString = new string_sj(s);
}
How do I add a constructor to class string_sj to allow this? I've tried
public:
string_sj(string & s) { string(s); }
and variation of this, but the compiler says: "redefinition of formal parameter 's' "
I have also tried
class string_sj : public string, string(string &) { ... }
but the compiler doesn't like that either.
I remember this topic being covered in the C++ class I took years ago, but I can't remember how to do it today.
K.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|