473,503 Members | 8,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a snippet of c++ code, i can't find the error?


this is the code:
#include<iostream.h>
#include<string.h>
int count=0;
class obj{
public :
obj();
~obj();
};
obj() {
++count;
cout<<count<<endl;
}
~obj(){
--count; cout<<count<<endl;
}
int main(){
obj A;

cout<<"begin block "<<endl;
obj B;
cout<<"end block"<<endl;

return 0;
}
where is the error? can someone point it out for me?
your help will be greatly appreciated.
best regards.

Oct 24 '06 #1
3 1239
try this:

#include<iostream // changed!
// changed!

int count=0;
class obj{
public :
obj();
~obj();
};

obj::obj() { // changed!
++count;
std::cout<<count<<std::endl; // changed!
}

obj::~obj(){ // changed!
--count; std::cout<<count<<std::endl; // changed!
}

int main(){
obj A;

std::cout<<"begin block "<<std::endl; // changed!
obj B;
std::cout<<"end block"<<std::endl; // changed!

return 0;
}

On Oct 24, 2:37 pm, "entrepreneur" <mailtumen...@gmail.comwrote:
this is the code:
#include<iostream.h>
#include<string.h>
int count=0;
class obj{
public :
obj();
~obj();};obj() {
++count;
cout<<count<<endl;}~obj(){
--count; cout<<count<<endl;}int main(){
obj A;

cout<<"begin block "<<endl;
obj B;
cout<<"end block"<<endl;

return 0;}where is the error? can someone point it out for me?
your help will be greatly appreciated.
best regards.
Oct 24 '06 #2
VJ
entrepreneur wrote:
this is the code:
#include<iostream.h>
#include<string.h>
int count=0;
class obj{
public :
obj();
~obj();
};
OBJ::obj() {
++count;
cout<<count<<endl;
}
OBJ::~obj(){
--count; cout<<count<<endl;
}
int main(){
obj A;

cout<<"begin block "<<endl;
obj B;
cout<<"end block"<<endl;

return 0;
}
where is the error? can someone point it out for me?
your help will be greatly appreciated.
best regards.
Oct 24 '06 #3
entrepreneur wrote:
where is the error? can someone point it out for me?
your help will be greatly appreciated.
best regards.
Is this a joke or a test? What makes you think that
there is an error?

-Martin

Oct 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9489
by: Andy Gayton | last post by:
Hey all, It looks like dynamic changes to a html document are only redrawn when the current code snippet comes to an end. For example the following page changes the text in a span, waits for a...
2
2576
by: Kavitha Rao | last post by:
Hi, I am getting the following errors while trying to run this snippet in Microsoft Visual C++.Can't seem to print the crc value stored. /* +++Date last modified: 05-Jul-1997 */ /* Crc - 32...
11
1458
by: alcastle | last post by:
I'm new to C. I have a snippet of code that works, but it's a little off in the output. I'm hoping someone can spot my error(s). I'm reading input from a serial device, and I need to print Hex,...
1
2593
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
1
1217
by: Hoopster | last post by:
Hello, I'm looking for a simple php snippet program. I have tried several and can't find exactly what I need. I'm actually looking for some sort of program where you can copy and past you php...
8
1985
by: Robert Dufour | last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com", "Test", "Test") Dim emailClient As New SmtpClient("localhost") emailClient.Send(message) The IIS server is...
6
3810
by: pamela fluente | last post by:
Hi, please find below a very simple code snippet which is giving me the following error: System.Runtime.Serialization.SerializationException was unhandled Message="The constructor to deserialize...
2
1955
by: daokfella | last post by:
Hi all, I've created a code snippet in VS 2005 and saved it in the proper snippet folder. When I right-click and select Insert Snippet, I navigation to My Code Snippets and it shows my snippet....
10
1316
by: nmehring | last post by:
I am writing some c++ code that interacts with a native C library and have to do some dynamic memory allocation to support it. I am getting memory leaks and I think this piece of code is the...
4
2183
by: tshad | last post by:
I was watching a video that used a code snippet to create a property and when you type "prop" tab tab, it would create the private variable as well as the property definitions with the private...
0
7207
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
7095
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
7294
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,...
0
7361
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...
1
7015
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
7470
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
5602
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
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.