Thread: can't figure it out

  1. #1

    can't figure it out

    What is wrong with this??
    It seems fine to me and uit gives me this error:

    20 return type specification for constructor invalid


    Main.cpp:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include "alarm.h"
    
    int main(int argc, char *argv[])
    {
      Alarm bug(4, BURGLAR);
      
      cout<<"4 Burglar alarms were installed\n";
      system("PAUSE");	
      return 0;
    }
    Alarm.h:
    Code:
    #ifndef ALARM_H
    #define ALARM_H
    #include <iostream.h>
    enum TYPE {FIRE, BURGLAR};
    class Alarm
    {
     public:
     
     Alarm();
     Alarm(int amount, TYPE type);
     ~Alarm();
     
     private:
     
     int theAm;
     TYPE itsType;
     
    }
    Alarm::Alarm()
    {
     cout<<"Constructer called...\n";
    }
    Alarm::Alarm(int amount, TYPE type)
    {
     theAm = amount;
     itsType = BURGLAR;
     cout<<"Constructer called...\n";
    }
    
    Alarm::~Alarm()
    {
     cout<<"Destructor called...\n";
    }
    #endif

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You forgot to put a semicolor after your class definition!

    Code:
    class Alarm
    {
     public:
     
     Alarm();
     Alarm(int amount, TYPE type);
     ~Alarm();
     
     private:
     
     int theAm;
     TYPE itsType;
     
    }; // See added semicolon

  3. #3

    Talking

    OMG sorry that was just rediculous
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    yeah, don't worry about it. weird stuff like that happens alot. it used to happen to me where I'd forget to put a semicolon on the last class definition in a header file so it would report errors on the files that included it, not in the header file itself! That musta happened to me 3 or 4 times heh. The errors are always misleading.

    After awhile you just get used to the fact that when you see an error that seems to make no sense at all, you either forgot a semi colon or a brace or something like that.

  5. #5
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    common mistakes by me:
    Code:
     char[25] string; // i always do this
    // --
    
    if(bar = foo) // i always forget the double =

  6. #6
    same here i do that all the time... sometimes i include homemade header files like this

    #include <homemade.h>

    anyway i need help. I made it a bit bigger and everything is fine only when i run it it doesn't show me the result i was expecting.

    Main.cpp:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include "alarm.h"
    void make(int, int, int);
    
    int main(int argc, char *argv[])
    {
      Alarm comp(4, BURGLAR, COMPUTER);
     //here burglar is supposed to be '1'
      cout<<comp.getType()<<endl; 
      
      make(comp.getAmount(), comp.getType(), comp.getRoom());
      Alarm kit(2, FIRE, KITCHEN);
     //and fire '0'
      cout<<kit.getType()<<endl;
      make(kit.getAmount(), kit.getType(), kit.getRoom());
      system("PAUSE");	
      return 0;
    }
    
    void make(int amount, int type, int room)
    {
     cout<<amount<<" ";
      switch(type)
      {
       case 0:
       cout<<"fire";
       break;
       case 1:
       cout<<"burglar";
       break;
       case 2:
       cout<<"window";
       break;
      }
        
      cout<<" alarms where installed in the ";
      switch(room)
      {
       case 0:
       cout<<"kitchen.";
       break;
       case 1:
       cout<<"living room.";
       break;
       case 2-4:
       cout<<"bed room.";
       break;
       case 5:
       cout<<"computer room.";
       break;
       case 6-7:
       cout<<"bathroom.";
       break;
       
      }
      cout<<"\n";
    }
    alarm.h:
    Code:
    #ifndef ALARM_H
    #define ALARM_H
    #include <iostream.h>
    enum TYPE {FIRE, BURGLAR, WINDOW};
    enum ROOM {KITCHEN, LIVING, BED1, BED2, BED3, COMPUTER, BATH1, BATH2};
    class Alarm
    {
     public:
     
     Alarm();
     Alarm(int amount, TYPE type, ROOM room);
     ~Alarm();
     ROOM getRoom() {return theRoom;}
     int getAmount() {return theAm;}
     TYPE getType() {return itsType;}
     private:
     
     int theAm;
     TYPE itsType;
     ROOM theRoom;
     
    };
    Alarm::Alarm()
    {
    }
    Alarm::Alarm(int amount, TYPE type, ROOM room)
    {
     theAm = amount;
     itsType = BURGLAR;
     theRoom = room;
    }
    
    Alarm::~Alarm()
    {
    }
    #endif
    for the enum TYPE all the values are one.(this is how i display them on the screen they all have a differnt value starting from 0 but i guess you allready knew that.)

    anyway it says that WINDOW BURGLAR and FIRE are all one making it come out wrong in the program.

  7. #7

    Talking

    and one more thing Polymorphic OOP because you wrote that long long very long post on classes i finally understood all about them

    THANK YOU
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    yeah i still do that sometimes, though not too much anymore

    char[size] Arrayname;

    It just seems more natural -- datatype then name!

    Gratefully, for some reason i never really forget the double equals. I have, however, sometimes mistakenly put double equals where i should put single equals. I think that's just because so many people always say it's such a common error that i subconsciously ALWAYS think double equals when i think of equals. Even when doing math on paper I write == instead of =.
    Last edited by Polymorphic OOP; 12-05-2002 at 05:48 AM.

  9. #9
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Thanks devour, glad it helped. I'd like to add more to it but I don't want to bring back an old topic. I'll prolly write a more detailed explanation sometime over winter break. I think I might write some stuff on other parts of the language as well, but I haven't really thought much about it yet. Prolly on arrays and pointers (as it's become apparent that for some reason many people, particularly in this forum, think that an array is a pointer while they are entirely different things). I might just do one on setting up a very general, very powerful gameloop, which would be neat and might be more interesting to people who already know the language well but are having trouble starting off on it's application to a complex game / interface. Depends on how much people really care.

  10. #10
    from what i have seen.. i care very much i'd probally read all of them! Your guide until was the first one that i've read that made it clear, simple, and fun to read. Please if you make any more tell me and i will read them.

    Now back to my original question... what is wrong with the above code?? four posts up I posted my revised edition of the arlarm system but something is very wrong just read the post it will tell you

    Thank you for any help you might give me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 10:43 AM
  2. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 05:22 PM
  3. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  4. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 01:47 AM
  5. ahh i can't figure out this loop
    By blindleaf in forum C Programming
    Replies: 1
    Last Post: 03-18-2003, 09:42 AM