Help!

This is a discussion on Help! within the C++ Programming forums, part of the General Programming Boards category; Hi guys. I have a problem here. Hope that some can help me out. I define 2 classes: Professor and ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    7

    Help!

    Hi guys.
    I have a problem here. Hope that some can help me out.
    I define 2 classes: Professor and Course.

    Course.h
    Code:
    #ifndef COURSE_H
    #define COURSE_H
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <boost/xpressive/xpressive.hpp>
    #include "Professor.h"
    
    using namespace std;
    using namespace boost::xpressive;
    
    class Professor;
    class Course{
    public:
    	    Course();
    	    Course(string courseCode,string courseName,int modularCredits,Professor newProfessor);
    	    void setProfessor(Professor professor);
    	    
    protected:
            Professor theProfessor();
    	    string courseCode;
    		string courseName;
    		int modularCredits;
    };
    #endif
    Course.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <boost/xpressive/xpressive.hpp>
    #include <sstream>
    #include "Course.h"	
    #include "Professor.h"
    
    using namespace std;
    using namespace boost::xpressive;
    Professor tmp;
    
    	Course::Course(string courseCode,string courseName,int modularCredits,Professor newProfessor)
    	{
    			setCourseCode(courseCode);
    			setCourseName(courseName);
    			setModularCredits(modularCredits);
    	        setProfessor(newProfessor);
    	}
    	void Course::setProfessor(Professor newProfessor)
    	{
    	 	 tmp.setName(newProfessor.getName());
    	 	 tmp.setGender(newProfessor.getGender());
    	 	 tmp.setIC(newProfessor.getIC());
    	 	 string line;
    	 	 line=tmp.getName();
    	 	 theProfessor.setName(line);
    	 	 line=tmp.getIC();
    	 	 theProfessor.setIC(line);
    	 	 line=tmp.getGender();
    	 	 theProfessor.setGender(line);
        }
    Professor.h
    Code:
    #ifndef PROFESSOR_H
    #define PROFESSOR_H
    #include <iostream>
    #include <string>
    #include <boost/xpressive/xpressive.hpp>
    #include "Person.h"
    #include "Course.h"
    using namespace std;
    using namespace boost::xpressive;
    
    class Course;
    class Professor:public Person{
    public:
         Professor();
         Professor(string name,string ic, string gender);
         
         static int lastAssignedID;
    protected:
    	 int staffID;
    	 vector<Course> teachingCourse;
    	 //vector<string> teachingCourses;
    };
    #endif

    Professor.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <conio.h>
    #include <vector>
    #include "Professor.h"
    //#include "Course.h"
    
    using namespace std;
    int Professor::lastAssignedID=0;
    
        Professor::Professor():Person()
        {}
    	Professor::Professor(string name, string ic, string gender): Person(name,ic,gender)
    	{
    	        staffID=lastAssignedID;
    	        lastAssignedID+=1;
    	}
    	
    	int Professor::getStaffID(){
    		  	return staffID;
    	}
    When I compile, the error is "insufficient contextual information to determine type".
    How can it be solved?
    Thank you.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Presumably "insufficient contextual information to determine type" is attached to some particular statement?

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    7
    Oh Yes.It attached to theProfessor.setName(line),theProfessor.setGender( line) and theProfessor.getIC(line).

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's an interesting error message -- is theProfessor declared anywhere? I don't see it. If you intend to use the newProfessor object passed in, you should do so. (And also, if you intend to modify the newProfessor object that was passed in, you need to pass it in by reference, as in Professor &newProfessor.)

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    How To Ask Questions The Smart Way
    Pick better titles as well
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    >>Professor theProfessor();
    This declares a function return a Professor that is named theProfessor. Probably not what you want.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

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