Class help (understanding)

This is a discussion on Class help (understanding) within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Stoned_Coder Code: #include <iostream> using namespace std; void results( Person& ); Based on what Stoned said, this ...

  1. #16
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Stoned_Coder
    Code:
    #include <iostream>
    
    using namespace std;
    
    void results(Person&);
    Based on what Stoned said, this should work:

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Person;
    void results(Person &P);
    the prototype results gets confused when you declare that its going to have an arguement of a class that isnt defined, or prototyped.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #17
    ------------
    Join Date
    Jun 2005
    Posts
    79
    i tried that, i think... or else i just got what you said confused and checked something else... sorry about that...
    CAUTION: Newbie at programming!
    -------------------------------------------------
    Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated

  3. #18
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Goosie
    i tried that, i think... or else i just got what you said confused and checked something else... sorry about that...
    It works for me, that was in reply to your original code that you couldnt get to work.. that why it wasnt working. Stoned pointed out correctly that your forgot the argument in results() prototype, but you also forgot to prototype the class since the results prototype requires it as its argument. Full code:

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Person;
    void results(Person &P);
    
    class Person {
    	public:
    		Person();
    		~Person();
    		string name;
    		int age;
    		string hobby;
    		int siblings;
    };
    
    Person::Person() {
    	cout<<"Constructor started... "<<endl;
    }
    
    Person::~Person() {
    	cout<<"YOU KILLED IT!!! "<<endl;
    }
    
    int main() {
    	Person Perso;
    	
    	cout<<"Whats your name? ";
    	cin>>Perso.name;
    	cin.get();
    	cout<<"How old are you? ";
    	cin>>Perso.age;
    	cin.get();
    	cout<<"Whats your hobby? ";
    	cin>>Perso.hobby;
    	cin.get();
    	cout<<"How many siblings do you have? ";
    	cin>>Perso.siblings;
    	cin.get();
    	results(Perso);
    }
    
    void results(Person &P) {
    	cout<<"Your name is: "<<P.name<<". "<<endl;
    	cout<<"You are "<<P.age<<" years old. "<<endl;
    	cout<<"Your hobby is "<<P.hobby<<". "<<endl;
    	cout<<"You have "<<P.siblings<<" siblings. "<<endl;
    }
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #19
    ------------
    Join Date
    Jun 2005
    Posts
    79
    Ok, i think i get it now but wount be able to check for a while... my brother spilled water all over my computer and its not working anymore so im on a windows labtop without a compiler... im going to try and get my computer working, or ask my mom if i can have her other one that she hasnt touched for like 6 months (even though i know for a fact she will say no...).. thanks for the help tho everyone...
    CAUTION: Newbie at programming!
    -------------------------------------------------
    Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well you spilled water on yours and broke it. Of course she's going to say no!


    Quzah.
    Hope is the first step on the road to disappointment.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  4. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 10:33 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21