By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Undefined constructor of std::string

P: n/a
My compiler's <string> header has this constructor
(after preprocessing):

template <class charT, class traits , class Allocator >
class basic_string
{
template <class InputIterator>
basic_string (InputIterator, InputIterator,
const Allocator& = Allocator()));

//.........
};

That means that some code like:
unsigned char a[10];
std::string s(a, a+10);

does not give a compiler error, but it does give a link error
because no body is ever defined for that constructor.

Should there be a body, or should this constructor not be
present at all? I have worked around it by writing my own
function body into <string> .

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Old Wolf wrote:
My compiler's <string> header has this constructor
(after preprocessing):

template <class charT, class traits , class Allocator >
class basic_string
{
template <class InputIterator>
basic_string (InputIterator, InputIterator,
const Allocator& = Allocator()));

//.........
};

That means that some code like:
unsigned char a[10];
std::string s(a, a+10);

does not give a compiler error, but it does give a link error
because no body is ever defined for that constructor.

Should there be a body, or should this constructor not be
present at all? I have worked around it by writing my own
function body into <string> .


You should avoid manually making changes to your compiler headers.
Perhaps you should contact your compiler vendor and find out why
your code isn't working. As to the body, the Standard does not
require any particular location of it anywhere. For all we know
you may be forgetting to include a particular C++ library when doing
the linking.

V
Jul 23 '05 #2

P: n/a
Old Wolf wrote:
My compiler's <string> header has this constructor
(after preprocessing):

template <class charT, class traits , class Allocator >
class basic_string
{
template <class InputIterator>
basic_string (InputIterator, InputIterator,
const Allocator& = Allocator()));

//.........
};

That means that some code like:
unsigned char a[10];
std::string s(a, a+10);

does not give a compiler error, but it does give a link error
because no body is ever defined for that constructor.
No, any standard compliant compiler should support this. gcc 3.2 does
support this. Sec 21.3 [lib.basic.string] specify this constructor.

Should there be a body, or should this constructor not be
present at all? I have worked around it by writing my own
function body into <string> .


I firmly believe that you know this is not a good idea. :)

Krishanu

--
"If you can't grow a skin 3 inches thick, then Usenet is probably not
for you."
--Dann Corbit

Jul 23 '05 #3

P: n/a
Krishanu Debnath wrote:
Old Wolf wrote:

That means that some code like:
unsigned char a[10];
std::string s(a, a+10);

does not give a compiler error, but it does give a link error
because no body is ever defined for that constructor.


No, any standard compliant compiler should support this.
Sec 21.3 [lib.basic.string] specify this constructor.
Should there be a body, or should this constructor not be
present at all? I have worked around it by writing my own
function body into <string> .


I firmly believe that you know this is not a good idea. :)


Not great, no, but contacting the compiler vendor is a far more
time-consuming and expensive option than my 2-minute fix.

I suppose the best thing to do might be to modify my code so
that it doesn't use on that constructor.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.