basic_string constructor

This is a discussion on basic_string constructor within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I want to study the constructor for string to see whether for an empty string it has some ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    basic_string constructor

    Hello everyone,


    I want to study the constructor for string to see whether for an empty string it has some default storage allocated or not (for self technical interest only), and string is defined based on basic_string<char>, so I begin to study basic_string.

    But in file string, there is no constructor for basic_string. Anything wrong? Where is it?

    I am using Visual Studio 2008.


    thanks in advance,
    George

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,203
    The default constructor for basic_string actually accepts an argument of type Allocator (with a default value).

    According to the C++ standard, the postconditions of that constructor are;

    1) the data() member function returns a non-NULL pointer that is copyable and can have 0 added to it.

    2) the size() member function returns zero

    3) capacity() yields an unspecified value.

    As to where the constructor is among VS2008's header files; I have not looked, so have no idea.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    MSVC's implementation defines the string class in <xstring>. This is done to break some header dependencies.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Recent versions of GCC use <bits/basic_string.h>, or maybe even .tcc, I can't remember at the moment. I don't know why this is -- and I know it's different in GCC 2.95. (Irrelevant. Oh well.)

    Also, going through header files isn't always the best way to find out whether something is so . . . it just tells you what your compiler thinks is so.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    Quote Originally Posted by CornedBee View Post
    MSVC's implementation defines the string class in <xstring>. This is done to break some header dependencies.
    I have found it according to your reply.


    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  2. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  3. Replies: 3
    Last Post: 03-25-2006, 11:59 PM
  4. How do I override constructor in inheritance?
    By Loduwijk in forum C++ Programming
    Replies: 13
    Last Post: 03-24-2006, 08:36 AM
  5. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 03:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21