std::string with non-type template arg

D

Default User

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
 
V

Victor Bazarov

Default said:
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
 
D

Default User

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top