home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Am I way off base? C++

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2466
Discussions: 200,961, Posts: 2,379,562, Members: 246,330
Old October 11th, 2004, 12:05 AM   Digg it!   #1 (permalink)
Ultimate Member
 
HeadBand's Avatar
 
Join Date: Dec 2003
Posts: 3,991
Am I way off base? C++

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?
Attached Files
File Type: zip cpp.zip (358 Bytes, 59 views)
__________________
Hey who turned sigs on?
HeadBand is offline   Reply With Quote
Old October 11th, 2004, 12:11 AM     #2 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,552
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
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
jkrohn is offline   Reply With Quote
Old October 11th, 2004, 12:31 AM     #3 (permalink)
Ultimate Member
 
HeadBand's Avatar
 
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
Attached Files
File Type: zip cpp.zip (352 Bytes, 37 views)
HeadBand is offline   Reply With Quote
Old October 11th, 2004, 01:11 AM     #4 (permalink)
Senior Member
 
TechKnickle's Avatar
 
Join Date: Aug 2004
Location: LA, California
Posts: 812
Send a message via AIM to TechKnickle Send a message via MSN to TechKnickle
What complier are you using?

DevC++? GNU? DM?
__________________
People are like coins, there's always two sides.
TechKnickle is offline   Reply With Quote
Old October 11th, 2004, 01:16 AM     #5 (permalink)
I am a banana!
 
originel's Avatar
 
Join Date: Jun 2002
Location: Texas Tech
Posts: 3,921
Send a message via AIM to originel
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.
originel is offline   Reply With Quote
Old October 11th, 2004, 02:18 AM     #6 (permalink)
Ultimate Member
 
HeadBand's Avatar
 
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
HeadBand is offline   Reply With Quote
Old October 11th, 2004, 08:18 PM     #7 (permalink)
I am a banana!
 
originel's Avatar
 
Join Date: Jun 2002
Location: Texas Tech
Posts: 3,921
Send a message via AIM to originel
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 .
originel is offline   Reply With Quote
Old October 11th, 2004, 11:19 PM     #8 (permalink)
Ultimate Member
 
HeadBand's Avatar
 
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
HeadBand is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
CANADIANS ARE GOING TO HELP AMERICA WITH THE WAR ON TERRORISM vass0922 IMO Community 35 November 20th, 2005 04:01 PM
Dumb cooking question.... F/A-18 MechDood IMO Community 10 April 17th, 2004 11:24 PM
Where do you go to get shirts printed? daveleau IMO Community 5 June 12th, 2003 02:13 AM
Need finding this workstation NDuser ResellerRatings Homepage Deals 5 February 13th, 2002 02:13 PM
My Athlon XP Temperatures vesther Processors, Memory, and Overclocking 23 January 29th, 2002 03:53 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2979)
The disrespect of Obama by Russian .. (46)
Making Health Care Worse (181)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
windows 7 problem (7)
Laptop with wireless problem. (5)
windows vista security holes (13)
Is the PSU I received dead? (13)
Print spooler problem (16)
Point and Shoot Camera Suggestions. (5)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
CPU fan stops spinning randomly (11)
Nvidia GTX 260 problem (1)
Modern Warfare 2: Who Bought It? (65)
Point and Shoot Camera Suggestions. (5)
Is the PSU I received dead? (13)
Print spooler problem (16)
windows vista security holes (13)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
Open With ..... Win7 (1)
webcam (0)
upgrade for hp a6101 (0)
Laptop with wireless problem. (5)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)


All times are GMT -4. The time now is 11:44 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28