Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheriting from std::string

Status
Not open for further replies.

chipperMDW

Programmer
Mar 24, 2002
1,268
US
I can't tell why VC++ doesn't like this code:

[tt]#include <string>

class Foo : public std::string
{
public:
Foo()
: string()
{}
};
[/tt]

VC++ seems to think that string is not a base or member of Foo. Putting &quot;std::&quot; before &quot;string&quot; in the initializer list produces the same error. However, putting &quot;using std::string;&quot; before the class declaration causes it to work fine. The code also works fine with any arbitrary classes and namespaces (say blah::Bar in place of std::string).

Is this a VC++ quirk, or am I using incorrect syntax? In the case of the latter, what would the correct syntax be (without using &quot;using&quot;)?
 
(No new post, just digging the original one up...)
 
I actually did some testing after your original post, and I couldn't make it work either.

My first thought was : Compiler error

But I have thought like that a number of times, and every time I found that the problems was in the source code.
Thus I was waiting for a good explanation from someone else ...
/JOlesen
 
Yeah, I tend to blame the code before the compiler... especially when it's mine. But I found some code on the C++ User's Journal site (I figure those guys know what they're doing) that does the same thing as mine, just with streambuf instead of string. That doesn't work on VC++ either, for the same reasons as mine. So I'm thinking compiler error now (something to do with the fact that string is a template, no doubt), unless someone else has something better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top