473,402 Members | 2,055 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,402 software developers and data experts.

strange class declaration

hi
i came across this following code could some one explain whats happening with the int refCount(ie.how can an argument be passed to an int) in constructor.

Expand|Select|Wrap|Line Numbers
  1. class SharedImage
  2. {
  3. public:    
  4.     SharedImage() : refCount(0){};
  5.     int refCount;
  6. };
Dec 25 '07 #1
2 1280
tomPee
21
hi
i came across this following code could some one explain whats happening with the int refCount(ie.how can an argument be passed to an int) in constructor.

Expand|Select|Wrap|Line Numbers
  1. class SharedImage
  2. {
  3. public:    
  4.     SharedImage() : refCount(0){};
  5.     int refCount;
  6. };
Hi,

SharedImage() is the constructor of the class, and it can intialize values ( even so before starting the body of the constructor, which is between the {}.

This code simply states that the constructor of sharedImage initializes the datamember 'refCount' at 0.

Initializating is needed when you:
- Have a const data member in your class
- Have a reference datamember in your class.
- Inherit some class that doesn't have a default constructor (= constructor that doesn't need any parameters ).

Putting:
SharedImage(){
refCount = 0;
}

Is not the same as initialization. As initialization is done before the constructor body even starts. The 3 thingies mentioned above have to be initialized.

-Tom
Dec 25 '07 #2
thanks........................ :)
Dec 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alexander Stippler | last post by:
Can someone explain the following construct to me: What is not clear to me is what the argument to foo is. A pointer to a member? template <class U> static char foo(void (U::*)(void)); ...
7
by: Anon Email | last post by:
Hi people, I'm playing around with Bartosz Milewski's code at the moment, and I got the following strange results upon execution of the code included further below. Please be aware that I...
2
by: Jason Heyes | last post by:
The following program does not compile. Apparantly "t" is inaccessible. #include <iostream> using namespace std; template <class T> class Foo { T t; public: Foo(T t_) : t(t_) { }
3
by: CHRISTOF WARLICH | last post by:
Hi, the following few lines of code are showing a quite strange and unexpected behaviour of namespaces that makes me worry wheater I should rely on namespaces in the future at all. The...
3
by: Alfonso Morra | last post by:
I have some code that I am porting over from C. It is full of static functions and global variables. I have got around this by wrapping most of the code in a singleton object. However, I am...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
3
by: Evangelista Sami | last post by:
hello i have this strange error message that i dont understand : _search.c: In function `_depth_search': _search.c:218: unable to find a register to spill in class `AREG' _search.c:218: this...
4
by: Harlan Messinger | last post by:
Since operator overloads into static functions in C#, there really doesn't need to be a connection between the types to which the operator is being applied and the type in which the overload is...
4
by: Valeriu Catina | last post by:
Hi, g++ gives the next error messages test.cpp: In function 'int main()': test.cpp:53: error: invalid conversion from 'int' to 'SmallVectorNoInit (*)()' test.cpp:53: error: initializing...
6
by: jdmuys | last post by:
Hi, I have a strange bug in my code, which I managed to reduce to the tiny C++ program below. The compiler reject the "class1<Type>::insideStruct *p2;" declaration with the following error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.