Class not recognized

This is a discussion on Class not recognized within the C++ Programming forums, part of the General Programming Boards category; When ever I write a class on one file, and try to use it on an other file, I get ...

  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,344
    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 06: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, 05:30 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 03:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21