0

So basically, I'm just messing around with classes and functions and such, and one thing I'd like to know is this:

Say I had this class, that derives off of std::string

class MyString : public std::string {
};

Because I'd like to create variables of type MyString that initializes the same way as std::string, I'd attempt to use:

using std::string::string;

However, this doesn't seem to work in Visual Studio - to VS, string() is not a member function.

This works in Code::Blocks / G++, why not Visual Studio / VC++?

Jay
  • 81
  • 1
  • 7

2 Answers2

3

According to MSDN, inherting constructors is not supported, at least in VS2013 or earlier versions.

But you shouldn't be inheriting from std::string anyway. No good will come from that. Write non-member functions if you want to extend the functionality of an existing class.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

Works in MSVC2015. VS2013 didn't support inheriting constructors

                           2010  2012  2013
Inheriting constructors    No    No    No

while MSVC2015 does (from preview on): http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx

As to why you shouldn't inherit from std::string, I recommend this post: Why should one not derive from c++ std string class?

Community
  • 1
  • 1
Marco A.
  • 43,032
  • 26
  • 132
  • 246