how to import classes in one class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maabar
    New Member
    • Aug 2006
    • 6

    how to import classes in one class

    Hi,
    can anybody tell me the codes to import more than one class, i.e. (.cpp) file, into another class?

    For example, if I have the following classes:
    "class1.cpp "
    "class2.cpp "

    and I want to declare objects of these classes in my main class: "MainClass. cpp"

    Do I need to declare header files for class1 and class2?

    Also, what would be the compiling commands to compile "Mainclass.cpp" ?

    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Yes include the header files for all the classes you wish to declare in your main class.

    And it rather depends on which compiler you are using.

    Comment

    • maabar
      New Member
      • Aug 2006
      • 6

      #3
      I am using g++ and I am using the following compiling commands:

      g++ -Wall -Lpath MainClass MainClass.cpp -o

      where path is the location of the directory that has my files.

      I am getting the following error messages:

      "In 'main': undefined reference to 'Class1::somefu nctions()':coll ect2:ld returened 1 exit status"

      Any suggestions?

      Comment

      Working...