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

E

entrepreneur

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.
 
H

heltena

try this:

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

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

obj::eek:bj() { // 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;
}
 
V

VJ

entrepreneur said:
this is the code:
#include<iostream.h>
#include<string.h>
int count=0;
class obj{
public :
obj();
~obj();
}; OBJ::eek:bj() {
++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.
 
M

Martin Steen

entrepreneur said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top