Am I way off base? C++  | |
October 11th, 2004, 12:05 AM
|
#1 (permalink)
| | Ultimate Member
Join Date: Dec 2003
Posts: 3,991
|
I am doing an independent study of c++, it is lead by a college student who give assignments but we are left to learn it ourself. The assignment is a debugging assignment and i have got it down to just a few syntax errors from what it was before but i can't seam to fix a few. He gave em a hint that they were usually in the previous line but i can't seam to find anything wrong with them. Is there smething simple i am missing or did i mess it up so much that its almost something else?
__________________
Hey who turned sigs on?
|
| |
October 11th, 2004, 12:11 AM
|
#2 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
|
Well you have messed up a few things.
1) you changed Banana to bob.
The bananna class need a default constructor. This is a Bananna() function.
You changed this default constructor to the name of your variable. This is wrong.
2) Don't put a ; after integer main(). This is only used when declaring functions for later definition. integer main needs to be int main()
3) take the ; off of class bananna.
You really tore that bad boy up  This should help get you started. After you make those changes, repost the code and waht the compiler spits at you.
Jkrohn |
| |
October 11th, 2004, 12:31 AM
|
#3 (permalink)
| | Ultimate Member
Join Date: Dec 2003
Posts: 3,991
|
ok i did that and played around with it a little now its saying
9 I:\cassign1.cpp syntax error before `{' token
I:\cassign1.cpp In function `int main()':
21 I:\cassign1.cpp `dostuff' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
now i am confused as to where it is getting bob from though |
| |
October 11th, 2004, 01:11 AM
|
#4 (permalink)
| | Senior Member
Join Date: Aug 2004 Location: LA, California
Posts: 812
|
What complier are you using?
DevC++? GNU? DM?
__________________
People are like coins, there's always two sides.
|
| |
October 11th, 2004, 01:16 AM
|
#5 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
|
first off, you need to remove the brackets around void dostuff(). the compiler thinks it's part of the constructor.
you also need to add the constructor code. currently it links to nothing. you could also take it out since it doesn't do anything.
you also need a ; after the last bracket on your class.
something like this: Code: #include <iostream> //removed .h
using namespace std; //changed io to ;
class banana
{
public: //added this line
void dostuff( ){cout << "I am a banana." << endl;}
};
int main() //changed integer to int
{
banana bob;
bob.dostuff ();
return 0; //added urn 0;
}
Last edited by originel : October 11th, 2004 at 01:19 AM.
|
| |
October 11th, 2004, 02:18 AM
|
#6 (permalink)
| | Ultimate Member
Join Date: Dec 2003
Posts: 3,991
|
i am using dev c++
thank you originel that worked but is there an easy way to leave the constructor code, he might have put it there for a reason but if it is overlycomplicated then he probobally meant to remove them |
| |
October 11th, 2004, 08:18 PM
|
#7 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
|
yeah sure it's easy. Code: #include <iostream> //removed .h
using namespace std; //changed io to ;
class banana
{
public: //added this line
banana();
void dostuff( );
};
int main() //changed integer to int
{
banana bob;
bob.dostuff ();
return 0; //added urn 0;
}
banana::banana()
{
}
void banana:dostuff()
{
cout << "I am a banana." << endl;
} some things to note are that i redid the setup a little. this is the normal and proper way to setup a class. basically the listing of banana(); and void dostuff(); in the class is now like a function prototype. This allows your functions to get really long without getting messy.
the banana:: bit just simply says that the function is part of the class and won't ever change for this class.
btw...does the banana thing happen to have anything to do with a short film called "Rejected" by don hertzfeld? "I am a banana" is a quote directly from it  . |
| |
October 11th, 2004, 11:19 PM
|
#8 (permalink)
| | Ultimate Member
Join Date: Dec 2003
Posts: 3,991
|
yeah i suspect he probobally just wanted us to remove it
and i don't know about that movie i'll ask the teacher he was the one who wrote the buggy version |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |