Thread: no... wtf!!!?? ( Global class is 'undeclared' )

  1. #1
    0x01
    Join Date
    Sep 2001
    Posts
    88

    no... wtf!!!?? ( Global class is 'undeclared' )

    Why the the hell is this happening????

    The setup
    Lets say I am writing a rectangle class called RECT (just an example). I would place the class in its own header file; while I would place its member function code it to its own cpp file.

    Problem
    K, in the rectangles cpp file that contains all of its member function code, I declare a "GLOBAL" RECT called 'rect'........

    Ok, back in main() WITH THE RECT HEADER FILE INCLUDED, I try to use this "GLOBAL" RECT called 'rect' that I defined earlier -> I get an error saying " 'rect' undeclared identifer ".... k..... thats a $$$$ing lie.

    Btw - I didn't place the GLOBAL RECT in any of the member functions, I just placed it above them all.

    COMPILER: VC++ OS: WindowsXP

    Another thing, sometimes VC++ will get stuck on an error... for instance, lets say I forgot to put a semi-colon at the end of a statement(Just an example), no seriously.... I correct the error, and it will give me the same $$$$ing error... So, to test it... I make an entirely different error on purpose, and it gives me the same error... and doesn't even bother looking at the error I did on purpose... Well, to test it further, I completely destroy all my code, delete imporant variables used through out the code, 'un-include' header files etc... and it will give me the same error.
    Then, I make a copy of all my code in my project, and delete the current project. Next, I create a new project in MSVC++ and add the code from the other project, and it compiles fine... Does anyone else have this problem??? (VC++ 6.0)

    Ok, ok, i know.. I didn't do a good job explaing any of this, I am being rushed right now.... I probably made many typo's and didn't make any sense........

    Any help would be appreciated.

    Any help would be appreciated...

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    Try the following:

    rect.cpp
    Code:
    RECT k;
    main.cpp
    Code:
    extern RECT k;

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Firstly, using "wtf" in your title makes you look childish and impatient...

    Secondly, have a look at the "extern" keyword

  4. #4
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    well about the same error thing even after youve fixed it, in the build menu, click clean solution and "clean <project name>". thats what it is in vc.net and try a "rebuild" too. doing that tends to help. it deletes the temporary files etc that are used by the linker and the compiler, so when you recompile it, fresh ones are made

  5. #5
    0x01
    Join Date
    Sep 2001
    Posts
    88
    Fordy, whats wrong with being a child (would you rather be an old man?)?

    Anyway, why should I have to use 'extern' ?? It SHOULD work fine without... shouldn't it? I don't understand...

  6. #6
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    you have to use extern because it's declared externally
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  4. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM