473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Doubt on Templates

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
5 1705
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

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

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
1
by: SK | last post by:
Hi all, I have a doubt in C++ Templates by Nicolai M. Josuttis. On Page 17 there is a line "In general, it is a good idea not to change more than necessary when overloading function templates....
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
3
by: darkstorm | last post by:
I have a doubt regarding inheritance involving templates Consider this: ///////////////////////////////////// template<typename T> class A { private: T m_a;
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
5
by: VSP | last post by:
Hi, I have a doubt regarding using references. Please look at the below code. I am using VC++ 6.0 int &i = 10; // Compilation error error C2440: 'initializing' : cannot convert from...
8
by: Tarique | last post by:
Hello. #include<stdio.h> int main(void) { int i=- -2; printf("%d",i); return 0; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.