English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

cout<<"begin block "< obj B;
cout<<"end block"<
return 0;
}
where is the error? can someone point it out for me?
your help will be greatly appreciated.
best regards.

2006-10-24 01:09:50 · 9 answers · asked by samurai 1 in Computers & Internet Software

9 answers

Dearest programmer,

Have you forgotten that constructor obj() belonging to class obj needs to defined in FULL FORM if declared outside the class definition. And as of the destructor, I feel if you have C compiler installed, it will not be allowed to be declared outside the class.
For declaring the constructor outside the class, use:
classname::classname()
{
// etc...
}
this format or declare it IN the class.
FOR the destructor,:
classname::~classname()
{
// etc...
}
will NOT work, just write the destructor inside the class.

The rest is OK, it would be nice if you had used delete to actually free the two objects : A and B, Since C does it on it's own, you will NOT be facing errors. But it is recommended for good programming practice.

2006-10-24 21:58:49 · answer #1 · answered by Rahul Ghose 4 · 0 0

Uh, that's one strange program you got there.
you have 'obj A;' and 'obj B;' but what's A and B?
If you're trying to write a program that does something, you could always ask for it and then you can examine the code. Write out part of the code and ask for help, otherwise people will think that you're just one of those stupid kids who are trying to cheat on their computer homework.
Also, provide the compiler or linker errors when you're asking what's wrong with your program.
It makes things easier.

2006-10-24 01:20:32 · answer #2 · answered by Balk 6 · 0 0

Try this piece of code

#include
#include
int count=0;
class obj{
public :
obj();
~obj();
};
obj::obj() {
++count;
cout< }
obj::~obj(){
--count;cout< }
int main(){
obj A;

cout<<"begin block "< obj B;
cout<<"end block"<
return 0;
}

2006-10-24 03:27:01 · answer #3 · answered by Nagesh K 2 · 0 0

--count;cout<
I'm not entirely sure about this, but shouldn't there be a space between the first semi-colon and the cout?

By the way, you can give us the error message, it makes things easier. Don't forget to compile the code.

2006-10-24 01:40:17 · answer #4 · answered by Anonymous · 0 0

}
~obj(){
--count;cout< }

put a space everytime you type "cout".

ex. cout << "count" << endl;

2006-10-24 01:15:07 · answer #5 · answered by Chameleon 3 · 0 0

verify your costs. I deleted the first one for "coloration:pink" and retyped it and the textual content is now pink. you are able to opt to envision all of your costs. I copied and pasted your code into Notepad and all of your costs are "dealing with" left. (closed). this is no longer interpreting any as being open costs.

2016-12-05 04:16:57 · answer #6 · answered by silender 4 · 0 0

try to compile it and see what error you get :)

2006-10-24 01:14:10 · answer #7 · answered by Anonymous · 0 0

It don't make sense that's what's wrong fella

2006-10-24 01:12:19 · answer #8 · answered by Anonymous · 0 1

well tell what are A , B

2006-10-24 20:14:33 · answer #9 · answered by Vaez 2 · 0 0

fedest.com, questions and answers