Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: question to...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 9497 of 9807
Post > Topic >>

Re: question to understand templates

by =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@[EMAIL PROTECTED] Apr 14, 2008 at 01:13 PM

On 14 Apr., 18:43, Bharath <tiromarc...@[EMAIL PROTECTED]
> wrote:
> Dear all,
> I'm trying learn templates concept.
>
> Here is a line of code from Bjarne Strustrup's C++ programming
> language 3rd edition:
>
> template<class C> struct String<C>::Srep
>
> I couldn't understand what the above line of code means. I'm expecting
> "struct/class <name>" after template<class C>. What exactly
> String<C>::Srep mean? Does "String" refer to STL's string template?

It cannot be the standard library's string class, because
this is located in namespace std (and thus would require
a leading std:: qualifier) and the full class template name
would be std::basic_string. std::basic_string still depends on
it's template parameters charT, traits, and allocator and
a typedef exists for charT = char and all remaining parameters
using some default types as std::string;

Without any further knowledge we can say that above
declaration specifies a class template String, which
depends on some type-parameter C. We can deduce this from
the combination of template<class C> with the name String.
The struct keyword before String<C>::Srep means that
we want to declare an *inner* class struct named Srep
inside the class template String. As written this
declaration is invalid. We can either declare Srep as
part of the class template definition String like this:

template<class C>
struct String { // Defines outer class (template) String
   struct Srep;  // Declares inner class Srep
};

or we can *define* String<C>::Srep out-of-class like
this:

template<class C>
struct String<C>::Srep {
   //...
};

Alternatively, we can also provide the definition of
Srep immediately at the point of it's declaration in
the hosting class template like this:

template<class C>
struct String { // Defines outer class (template) String
   struct Srep { // Defines inner class Srep;
     //...
   };
};

Without using templates you can compare your original
declaration with something like this:

struct StringType { // Defines outer class String
   struct Srep; // Declares inner class Srep
};

// Defines inner class Srep outside of the class StringType:
struct StringType::Srep {
};

HTH & Greetings from Bremen,

Daniel Krügler


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
question to understand templates
Bharath <tiromarch08@[  2008-04-14 10:43:12 
Re: question to understand templates
"Bo Persson" &l  2008-04-14 12:53:06 
Re: question to understand templates
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-14 13:13:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 19:49:14 CDT 2008.