Thread: Internal Compiler Error?

  1. #1

    Angry Internal Compiler Error?

    I am just practicing using classes so that I better understand how they work and such but I have ran into an error which I do not understand. Here is my code-
    Code:
    #include <iostream>
    using namespace std;
    
    class Teacher
    {
    	public:
    		Teacher();
    		void SetRoomNumber(int RoomNum);
    		int GetRoomNumber();
    	private:
    		int RoomNumber;
    }
    
    Teacher::Teacher
    {
    	SetRoomNumber(0);
    }
    
    Teacher::SetRoomNumber()
    {
    	RoomNumber = RoomNum;
    }
    
    Teacher::GetRoomNumber()
    {
    	return RoomNumber;
    }
    
    int main()
    {
    	Teacher Stone, Hill;
    	cout << Stone.GetRoomNumber();
    	cout << Hill.GetRoomNumber();
    	Stone.SetRoomNumber(219);
    	Hill.SetRoomNumber(221);
    	cout << Stone.GetRoomNumber();
    	cout << Hill.GetRoomNumber();
    	return 0;
    }
    The compiler error-
    fatal error C1001: INTERNAL COMPILER ERROR
    (compiler file 'msc1.cpp', line 1786)
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
    Error executing cl.exe.
    I am pretty sure it isn't my code by the way the error code is. But I would appreciat some help.


    EDIT: Also when you create your own constructor, is it a good habit to create a destructor even if it takes no action?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    18
    Your answer is here, go here if you want to find your answer because here's where it is:

    http://owlnext.sourceforge.net/qa51.html
    ~Sean Michael Simonsen

  3. #3
    I saw that on line 15 when declaring my constructor I forgot to put my ()'s so now I get 4 errors (none are internal compile errors).

    The error messages are-
    C:\Documents and Settings\Owner\Desktop\C++\school IO\teacher-class.cpp(15) : error C2533: 'Teacher::Teacher' : constructors not allowed a return type
    C:\Documents and Settings\Owner\Desktop\C++\school IO\teacher-class.cpp(20) : error C2511: 'SetRoomNumber' : overloaded member function 'int (void)' not found in 'Teacher'
    C:\Documents and Settings\Owner\Desktop\C++\school IO\teacher-class.cpp(5) : see declaration of 'Teacher'
    C:\Documents and Settings\Owner\Desktop\C++\school IO\teacher-class.cpp(31) : error C2264: 'Teacher::Teacher' : error in function definition or declaration; function not called
    C:\Documents and Settings\Owner\Desktop\C++\school IO\teacher-class.cpp(31) : error C2264: 'Teacher::Teacher' : error in function definition or declaration; function not called
    Error executing cl.exe.
    I am too much of a newbie to know what these errors are trying to tell me. Can anyone help me out?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    instead of calling a function in the constructor, why not just set the private data member to zero.

    Code:
    RoomNumber = 0;
    //instead of
    SetRoomNumber(0);

  5. #5
    I didn't think you could initialize a data member like that... Lemme try it out.

    EDIT: Apperently I was correct.
    teacher-class-bkup.cpp(10) : error C2252: 'RoomNumber' : pure specifier can only be specified for functions
    Last edited by Munkey01; 02-03-2003 at 10:42 PM.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you could and it is more efficient, faster because it doesn't have to call the function...

    not sure if it fixes the error though, but i think it may.

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    You have no closing ; on your teacher class, this confuses the hell out of the compiler. SetRoomNumber needs to have the return type and paramiter
    void Teacher::SetRoomNumber(int RoomNum)
    GetRoomNumber needs a return type
    int GetRoomNumber()
    The constructor will then work with RoomNumber = 0; It is pereferable to use initalization lists whenever possible, the syntax is strange but you should get used to it
    Teacher::Teacher() : RoomNumber(0) {
    }
    This looks like a constructor call, and it is, the advantage here is that if you don't do this the default constructor of all your member variables is called before you reach the { of the ctor. In the case of an int this makes not the slightest difference, but you should become familliar with the syntax.

  8. #8
    Well what about if I just declare the functions in the class?

    Ex.
    Code:
    void SetRoomNumber(int RoomNum) { RoomNumber = RoomNum; }
    int GetRoomNumber() { return RoomNumber; }
    Is that a bad way of doing it?

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    Not at all a bad way of doing it, those are known as inline funtions. The advantage is that they are faster, the disadvantage is that they bloat up your program and slow down compilation. I generally make just about everything inline. I also spend a great deal of time waiting for stuff to compile and thus hanging out on message boards.

  10. #10
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Well said, grib :)

    this confuses the hell out of the compiler
    Yeah, this is something to be aware of. When the compiler gets confused, the error messages can be incorrect and misleading. Compilers get confused often! Once, I made a little copy and paste error, misplacing a curly bracket, and the compiler reported hundreds of errors. I had to comment-out lots of code to narrow-down the actual error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM