#include <iostream.h>
class cat
{
public:
int setAge();
int getAge();
private:
int Age;
};
cat::setAge(int):
{
}
cat::getAge();
{
return Age;
}
main()
{
setAge(5);
cout << getAge();
return 0;
}
What's wrong with this code?
#include <iostream.h>
class cat
{
public:
int setAge();
int getAge();
private:
int Age;
};
cat::setAge(int):
{
}
cat::getAge();
{
return Age;
}
main()
{
setAge(5);
cout << getAge();
return 0;
}
What's wrong with this code?
-Dean
that should work.Originally posted by DeanDemon
#include <iostream.h>
class cat
{
public:
int setAge(); // needs to be setAge(int x); need that variable
int getAge();
private:
int Age;
};
cat::setAge(int x)//no semicolon, or colon here, notice variable here
{
Age = x;
}
cat::getAge()//no semicolon here
{
return Age;
}
main()
{
setAge(5);
cout << getAge();
return 0;
}
What's wrong with this code?
>>What's wrong with this code?
It's not in code tags
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
There are a few other problems with this code:
1. setAge() is decalared as returning a value, however it doesn't.
2. You need to instantiate the class in order to access its member functions.
i.e.
3. getAge() is declared without a type, as you are returning an int it should be declared as such.Code:int main(void) { cat Foo; Foo.setAge(5); cout << Foo.getAge(); return 0; }
Code:int getAge(void); // and later: int cat::getAge(void) { return Age; }
Last edited by foniks munkee; 12-06-2002 at 02:41 AM.
"Queen and huntress, chaste and fair,
Now the sun is laid to sleep,
Seated in thy silver chair,
State in wonted manner keep."
Then I should know how to fix your problem, but that title's what I call "manipulation". If I were these people here, I would have flamed you instead of helped you; you're very lucky that I wasn't the first person to reply.If You're Any Good At C++, You Should Know How To Fix My Problem.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
wow, I didn't even think about the other possible errors. oops...
I'd have thought that main has to be intiated. Unless this is just what people get taught?
**********************
*==================*
* Many Can. One Must... *
*==================*
**********************
If you are talking about having main return an int, yes - I typoed.. main should return an int. Otherwise I am not sure what you mean.
"Queen and huntress, chaste and fair,
Now the sun is laid to sleep,
Seated in thy silver chair,
State in wonted manner keep."
Well I guess I'm too late for that too.Originally posted by Hunter2
Then I should know how to fix your problem, but that title's what I call "manipulation". If I were these people here, I would have flamed you instead of helped you; you're very lucky that I wasn't the first person to reply.
>> If You're Any Good At C++, You Should Know How To Fix My Problem.
OOoooo...that sounds like a challenge.
[note to self]This post would have been much funnier if it was at the beginning of the thread...[/note]
Are you saying you're not good at C++ and this is a desperate cry for help, or that you're such a newbie that you need to pressure people in here, even when you have no room to talk?If You're Any Good At C++, You Should Know How To Fix My Problem.
Stan The Man. Beatles fan
When I was a child,
I spoke as a child,
I thought as a child,
I reasoned as a child.
When I became a man,
I put childish ways behind me"
(the holy bible, Paul, in his first letter to the Cor. 13:11)
>What's wrong with this code?
it has errors in it. ask nice, and people might even help you fix them
>What's wrong with this code?
Basic: You should be able to fix basic errors yourself.
Advanced: You are using a totally outdated header file.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Now guys i ad mit when i first saw this topic i thought "WTF?", but is it not possible that we have interpretted it the wrong way? Maybe he/she meant to say it like;
"wow my question is really basic, so anyone with some experience should be able to help me narrow down the problem i can't find."
But instead we took it wrong and got on his case? All i am saying is maybe he didn't mean it to come across as it did and we shouldn't ridicule him(yet).
true.. but s/he should have been more specific. isn't it against the rules to just post some code and say "what's wrong with this?", anyway? i think i read that somewhere...
any compile errors (which i'm sure there were some) should have been listed, and a more specific question should have been asked.. not to mention s/he should have checked the FAQ/used the search button/put forth some effort to figure it out first. but i guess we'll put that aside
just my two cents...