Thread: Help! Error!!!!

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    Help! Error!!!!

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    class course
    {
    	private:
    		string name;
    		int credits;
    		int total;
    	public:
    		string getinfo()
    		{
    			int total;
    			cout << "Please ask student the number of courses taken: " << endl;
    			cin >> total;
    			cout << "Test print of " << total << endl;
    		}
    	void printIt()
    	{
    		cout<<"Total courses: "<<total<<endl;
    	}
    	
    	~course()
    	{
    		cout<<"Destructor is called " <<endl;
    	}
    };
    
    class registration:public course
    {
    	private:
    			char *ptr;
    			int credits;
    			string classes;
    			string total;
    	public:
    		void printinfo();
    		
    		registration();		
    	//	~registration();
    
    	void printIt()
    	{
    		course::printIt();
    	}
    	
    	~registration()
    	{
    		cout<<"Destructor is called " <<endl;
    	}
    };
    
    registration::registration()
    
    {
    	cout << "Enter class information that student is signing up for." << endl;
    	getline(cin,classes);
    	cout << "Please enter the total number of credits the student is signed up for." <<endl;
    	cin >> credits;
    
    };
    
    /*registration::~registration()
    
    {
    
    	cout << "Student x is signed up for: " << classes << endl;
    	cout << "Total number of credits signed up for = " << credits << endl;
    
    };*/
    
    void registration::printinfo()
    {
    	cout << "Student x signed up for: " << total << endl;
    
    };
    int main()
    {
    	course *p;
    
    	string id;
    	registration *ptr;
    	p.printIt();                  (THIS IS THE PROBLEM LINE)
    	
    	cout<<"Ask student of courses she or he is registering."<<endl;
    	getline(cin,id);
    
    	return 0;
    }

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    what is the error? what compiler?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    im compiling in visual studio C++ its telling me " : error C2228: left of '.printIt' must have class/struct/union type" i dont understand what its asking for! I'm really new at this and im not very good with solving errors!!!

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    p is a pointer, so you should use the -> operator:

    Code:
    p->printIt();
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    Thanks that cleared up my errors, but no i have a warning for the PTR.

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Equivalently, p->printIt() is the same as (*p).printIt() though the first is prefered.

    Helps to know what the warning is, but my guess is that it is just mentioning that you have an unused variable. This just means that ptr never actually does anything, and does not need to be there.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    Yeah it is saying that ptre is an unused variable, BUT when i run the program with the warning VISUAL STUDIO CRASHES!! Somethings deffinitly wrong!! i just dont understand there has to e something im not seeing!!!

    Thanks!

  8. #8
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    The pointer of p is not pointing to anything. You need to initialize the pointer first.
    Code:
    course* p = new course;
    ...
    delete p;
    And DON'T forget to delete the memory used by new before the program exits.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM