i'm newbie of C++ Language..
What i habe seen is this..
MemoryFile( char * in_name = NULL )
: name(NULL), data(NULL), size(0), position(0) {
// <-----------HIER
if( in_name != NULL ) // Copy the input name.
name = in_name;
}
this is a Constructor of some Class..
my Question is....
what is this ---> " : name(NULL), data(NULL), size(0), position(0) "
is this another Input Arguments ??
normaly i have seen always this form of Constructors..
NameOfClass(Input Arguments){
Some Initialization....
}
thanks to read.. 4 1667
kleinstein wrote: i'm newbie of C++ Language..
What i habe seen is this..
MemoryFile( char * in_name = NULL ) : name(NULL), data(NULL), size(0), position(0) { // <-----------HIER if( in_name != NULL ) // Copy the input name. name = in_name;
This is silly, it should be replaced with name(in_name) in the
initialiser list.
} this is a Constructor of some Class..
my Question is.... what is this ---> " : name(NULL), data(NULL), size(0), position(0) " is this another Input Arguments ??
It is an initialiser list, look it up in your C++ book. These are
preferred because they enable the compiler to generate more efficient
code and are more concise than individual assignments in the constructor
body..
--
Ian Collins.
On Tue, 30 May 2006 20:26:11 +1200, Ian Collins wrote: kleinstein wrote: i'm newbie of C++ Language..
What i habe seen is this..
MemoryFile( char * in_name = NULL ) : name(NULL), data(NULL), size(0), position(0) { // <-----------HIER if( in_name != NULL ) // Copy the input name. name = in_name;
This is silly, it should be replaced with name(in_name) in the initialiser list.
Depends on what type name is. If it's a std::string, no it shouldn't.
You can't initialize a std::string with NULL.
Andre Kostur wrote: On Tue, 30 May 2006 20:26:11 +1200, Ian Collins wrote:
kleinstein wrote: i'm newbie of C++ Language..
What i habe seen is this..
MemoryFile( char * in_name = NULL ) : name(NULL), data(NULL), size(0), position(0) { // <-----------HIER if( in_name != NULL ) // Copy the input name. name = in_name;
This is silly, it should be replaced with name(in_name) in the initialiser list.
Depends on what type name is. If it's a std::string, no it shouldn't. You can't initialize a std::string with NULL.
Then the original code would be broken as well as it does name(NULL) in
the initialiser list.
It could be a somewhat odd class however that handles constructing with
NULL gracefully but not assigning NULL.
On Tue, 30 May 2006 06:51:19 -0700, Markus Schoder wrote: Andre Kostur wrote: On Tue, 30 May 2006 20:26:11 +1200, Ian Collins wrote:
> kleinstein wrote: >> i'm newbie of C++ Language.. >> >> What i habe seen is this.. >> >> >> MemoryFile( char * in_name = NULL ) >> : name(NULL), data(NULL), size(0), position(0) { >> // <-----------HIER >> if( in_name != NULL ) // Copy the input name. >> name = in_name; > > This is silly, it should be replaced with name(in_name) in the > initialiser list.
Depends on what type name is. If it's a std::string, no it shouldn't. You can't initialize a std::string with NULL.
Then the original code would be broken as well as it does name(NULL) in the initialiser list.
It could be a somewhat odd class however that handles constructing with NULL gracefully but not assigning NULL.
Yikes! You're right. Missed the initialization of name in the initializer
list. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sandy |
last post by:
Is there any way to write a "single constructor" that can be called using
either 1 or 2 arguments. But without using default arguments.
Actually i don't need this. Just asking as some other guy...
|
by: ben |
last post by:
getting a bit confused with the details of how c's grammar is
specified, especially when you get self-reference like in this:
postfix-expression:
primary-expression
postfix-expression ...
|
by: Magius |
last post by:
Hello,
I have a question about the correctness of the language grammar for the C#
2.0 specification. I am working with the grammar specified in the June 2005
ECMA-334 standard.
Basically, a...
|
by: Remco van Engelen |
last post by:
Hello,
I have a question regarding the ISO C grammar. The syntax of a
direct-declarator reads (section A.2.2, page 413 in my copy; the (R1)
is just to 'name' the rule for later reference):
...
|
by: Simon |
last post by:
I'm trying to understand pointers in a little more detail, and have
written a test program (reproduced below) to experiment with passing
pointers between functions.
Thinking only about the...
|
by: iluvatar |
last post by:
Hi all.
I have written a 3d-vector class (for 3-dimensional space) and I have
overloaded the arihtmetic operators like +, +=, * and so on. Also, the
constructor works with doubles and has...
|
by: fdmfdmfdm |
last post by:
Associativity in C takes two forms: left to right and right to left. I
think the K&R book lacks something...
For example, *p++, since the associativity is from right to left, do
this expression...
|
by: sovixi |
last post by:
Hi,
Hi I have a question concedrning grammar correction. What steps do you think are included in GC process? That’s what I have so far:
1. Find each sentence in a text
2. Look up words in the...
|
by: Ryan Krauss |
last post by:
I need to parse the following string:
$$\pmatrix{{\it x_2}\cr 0\cr 1\cr }=\pmatrix{\left({{{\it m_2}\,s^2
}\over{k}}+1\right)\,{\it x_1}-{{F}\over{k}}\cr -{{{\it m_2}\,s^2\,F...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |