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

std::string with non-type template arg

P: n/a
I received some code from another programmer who happens to be out of
town. In this, he had something like:

struct st
{
std::string s<20>;
};

Looks like it's setting the string size.

VC++ 6 produced an error in compilation, complaining of a syntax error
before the <20> part. I looked at Stroustrup and Josuttis to see if I
could find something about a non-type template argument for doing this,
and didn't really see anything, although I may have just not realized I
was seeing it. I didn't see any examples similar to this either.

Normally when I want to specify string size at declaration, I use the
constructor:

std::string s(20, 0);
Presumably this guy had compiled it on whatever platform he uses
without problem, although I can't check with him. Is this an error on
his part, or yet another VC++ template problem?


Brian
Aug 4 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Default User wrote:
I received some code from another programmer who happens to be out of
town. In this, he had something like:

struct st
{
std::string s<20>;
};

Looks like it's setting the string size.

VC++ 6 produced an error in compilation, complaining of a syntax error
before the <20> part. I looked at Stroustrup and Josuttis to see if I
could find something about a non-type template argument for doing this,
and didn't really see anything, although I may have just not realized I
was seeing it. I didn't see any examples similar to this either.

Normally when I want to specify string size at declaration, I use the
constructor:

std::string s(20, 0);
Presumably this guy had compiled it on whatever platform he uses
without problem, although I can't check with him. Is this an error on
his part, or yet another VC++ template problem?


The code presented isn't C++. As to VC++, ask in
microsoft.public.vc.language.

V
Aug 4 '05 #2

P: n/a
Victor Bazarov wrote:

The code presented isn't C++.
That's all I needed to know.
As to VC++, ask in microsoft.public.vc.language.


As it seems to be correctly diagnosing a syntax error, that doesn't
seem needful.


Brian

Aug 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.