Thread: Constructors now allowed a return type: Mystery Error

  1. #1
    Polar Fuzz
    Join Date
    Oct 2003
    Posts
    36

    Unhappy Constructors now allowed a return type: Mystery Error

    I get the following two errors:

    "constructors not allowed a return type"
    "Student followed by int is illegal, did you forget a ';' "

    I got these errors before and the code is extremely simple. If I remark the constructor, it stops at the other constructor as well. There is no return type of the constructor. The only way I could fix it previously was to delete the project and then recreate it, and overlay another project's code as a template. I would then modify it back to the code it is supposed to be. The error then seems to go away and I have no idea why it works when the resulting code seems to be exactly the same as the one that did not work. It seems to be a mystery. I started a CLASS and everything was fine until I added another class implementation file.

    Partial code below:

    Code:
    (Student.h file)
    
    Public:
    
         Student();  // constructor
         Student (char *, char *, char *);
    
    (Student.cpp: Implementation)
    
    #include <iostream>
    
    using namespace std;
    
    #include "Student.h"
    
    Student::Student ()  { }  //"constructors not allowed a return type" error stops here
                             // There is obviously no return type!
    
    Student::Student (char* first, char* last, char* street)
    {
    ......  // if above remarked out, compilation stops here....
    }
    
    (school.cpp:  Driver)
    
    #include <iostream>
    
    using namespace std;
    
    include "Student.h"
    
    // "Student followed by int is illegal, did you forget a ';' "
    // Error points to this location
    // Semicolon not needed on line above!
    
    int main ()
    {
    
    return 0;
    }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You're almost certainly missing a semicolon after the class declaration:
    Code:
    class Student {
    ...
    };  <-
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Polar Fuzz
    Join Date
    Oct 2003
    Posts
    36
    That did it! Thanks. Gee Wiz, you would think the compiler should just tag that one!

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Definitely should, and I think VC++.Net 2003 does. But there's some peculiar heritage from C that makes it not that easy.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM