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

Doubt on Templates

P: n/a
Hi Friends,

I have subscribed to this group recently. I have a doubt in templates
in C++

A fraction of code given in "The C++ Programming Language" -By
B.Stroustrup is as follows :

template<class T, int i> class Buffer {

T v[i];
int sz;

public :
Buffer() : sz(i) { }
//......
};

i couldn't understand the statement

" Buffer() : sz(i) { } "

can u please describe the statement for me ...... please......

Thanks.

Jun 1 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
edu.mvk wrote:
Hi Friends,

I have subscribed to this group recently. I have a doubt in templates
in C++

A fraction of code given in "The C++ Programming Language" -By
B.Stroustrup is as follows :

template<class T, int i> class Buffer {

T v[i];
int sz;

public :
Buffer() : sz(i) { }
//......
};

i couldn't understand the statement

" Buffer() : sz(i) { } "
That :sz(i) part initializes member sz with i.

can u please describe the statement for me ...... please......

Thanks.

Jun 1 '06 #2

P: n/a

edu.mvk wrote:
Hi Friends,

I have subscribed to this group recently. I have a doubt in templates
in C++

A fraction of code given in "The C++ Programming Language" -By
B.Stroustrup is as follows :

template<class T, int i> class Buffer {

T v[i];
int sz;

public :
Buffer() : sz(i) { }
//......
};

i couldn't understand the statement

" Buffer() : sz(i) { } "

can u please describe the statement for me ...... please......

Thanks.


In the above template class declaration the variable i in the syntax
<class T, int i>
is called non-type argument.
These are constant variables with in the class.
coming to your doubt

Buffer() : sz(i) { }

the value sz is initialized to the value of i.

Regards
Sunil

Jun 1 '06 #3

P: n/a

edu.mvk wrote:
Hi Friends,

I have subscribed to this group recently. I have a doubt in templates
in C++

A fraction of code given in "The C++ Programming Language" -By
B.Stroustrup is as follows :

template<class T, int i> class Buffer {

T v[i];
int sz;

public :
Buffer() : sz(i) { }
//......
};

i couldn't understand the statement

" Buffer() : sz(i) { } "

can u please describe the statement for me ...... please......

Thanks.


In the above template class declaration the variable i in the syntax
<class T, int i>
is called non-type argument.
These are constant variables with in the class.
coming to your doubt

Buffer() : sz(i) { }

the value sz is initialized to the value of i.

Regards
Sunil

Jun 1 '06 #4

P: n/a

Sunil Varma wrote:
edu.mvk wrote:
Hi Friends,

I have subscribed to this group recently. I have a doubt in templates
in C++

A fraction of code given in "The C++ Programming Language" -By
B.Stroustrup is as follows :

template<class T, int i> class Buffer {

T v[i];
int sz;

public :
Buffer() : sz(i) { }
//......
};

i couldn't understand the statement

" Buffer() : sz(i) { } "

can u please describe the statement for me ...... please......

Thanks.


In the above template class declaration the variable i in the syntax
<class T, int i>
is called non-type argument.
These are constant variables with in the class.
coming to your doubt

Buffer() : sz(i) { }

the value sz is initialized to the value of i.

Regards
Sunil


Sorry for the re-post.

Jun 1 '06 #5

P: n/a
edu.mvk posted:
" Buffer() : sz(i) { } "

Your query isn't to do with templates -- it's to do with classes in
general.
What you see above is a contructor initialisation list. It's explained in
the newsgroup FAQ.
-Tomás
Jun 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.