Thread: Class not recognized

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    Class not recognized

    When ever I write a class on one file, and try to use it on an other file, I get errors like 'error C2065: 'MyClass' : undeclared identifier'.
    I learnt that only if the class declaration appears in the same file, and before the line it is used, only then my project will compile.
    I'm pretty sure theres something simple that I'm doing wrong... How do I solve this?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You have to #include the header file where you defined the class.

    If you didn't define the class in a header, then you need to do that and include the header in the source files that use that class.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    Thank you for your quick reply
    Last edited by Vall3y; 10-11-2009 at 05:37 PM.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    I think buddy u r writing your class in your .cc/.cpp file and then try to use it there or your are writing your class in your header file and then try to use it

    just declare your calss in a header file and include it where ever you want

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM