Having problems with classes

Dec 10, 2008 at 9:53am
I have finals tomorrow and I'm still having some problems with classes. It's 4 in the morning and I have a test at 7:30 and still trying to go over it. I'm looking over the review now. Please help me with this question.

He wants to know what the output would be. He likes to trick people so I'm getting more and more confused. I would say this program would fail. I understand that this isn't a whole program but I don't think this makes sense. Will someone please... reassure me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class catType
	{
	private: 
		int x; 
	public: 
		cat(){x=10; cout<<"Meow"<<endl;}
		~cat(){cout<<x<<" Meow again"<<endl;}
	}

	void fun()
	{
		catType myCat; 
	}

	int main ()
	{
		fun(); 
		return 0; 
	}


Dec 10, 2008 at 10:55am
A semicolon is missing after the } at the end of catType.

1
2
3
class catType {

}; // here 


So other than that (+ you need to include iostream, of course), the output should be:
1
2
Meow
10 Meow again
Dec 10, 2008 at 11:04am
But because the fun() functions only creates an instance of the class. There would be no output? As your not calling the functions to display the "meow" etc
Dec 10, 2008 at 11:17am
Thats what I thought Mythios.. but I'm not sure.. he tends to use the exact same problems from the review so I wanted to make sure.. but I guess if he does use the same exact same problem, I'll just write the program will not run because he forgot the ; and I will still be right.. :) right? haha
Dec 10, 2008 at 11:21am
Well if he marks you wrong you can print this page out and slap him with it :)
Dec 10, 2008 at 11:26am
haha is a bit of a scatterbrain.. haha but thanks for the help!!! :)
Dec 10, 2008 at 11:26am
No problem - good luck with your final!
Dec 10, 2008 at 11:31am
I read too quickly. I blame the coffee. =)

Good luck!
Dec 10, 2008 at 11:35am
For me Coke > Coffee Unless I'm at a starbucks ;)
Dec 10, 2008 at 11:44pm
A semicolon is missing. Is the point of the question really just to spot the missing semicolon? "Well you see, the class definition is missing a semicolon. That was the answer to the question. Didn't you get it? HA!" I hate questions like that. I thought compilers were built to deal with such details.

I have finals tomorrow and I'm still having some problems with classes...

He wants to know what the output would be. He likes to trick people so I'm getting more and more confused. I would say this program would fail.


You really should write "This program is an EPIC FAIL" on the paper. That would be funny.
Topic archived. No new replies allowed.