Problem with including a class in my program

This is a discussion on Problem with including a class in my program within the C++ Programming forums, part of the General Programming Boards category; I'm new to programming, and i have a big problem with C++ classes, or more importently, including the classes in ...

  1. #1
    Registered User TheYeIIowDucK's Avatar
    Join Date
    Aug 2010
    Posts
    3

    Problem with including a class in my program

    I'm new to programming, and i have a big problem with C++ classes, or more importently, including the classes in my main.cpp file.
    I have 2 files in one folder, main.cpp and myclass.cpp
    The myclass.cpp one works fine, but i just can't put its functions into the main.cpp scope! I tried to use the old ".h" headers, but that makes things even MORE complicated and it doesn't work either. From what i understand, the .h files are an outdated C feature, so in C++ you should be able to include non-.h files.
    Here are the 2 files:
    main.cpp
    Code:
    #include <iostream>
    #include <myclass>
    
    using namespace std;
    
    int main()
    {
        cout << "Hello world!" << endl;
        return 0;
    }
    myclass.cpp
    Code:
    #include <iostream>
    
    using namespace std;
    
    class myclass
    {
        public:
            myclass();
            virtual ~myclass();
        protected:
        private:
    };
    
    myclass::myclass()
    {
        //ctor
    }
    
    myclass::~myclass()
    {
        //dtor
    }
    
    //More functions will go here
    I tried lots of things:
    #include <myclass.cpp>
    #include "myclass"
    #include "myclass.cpp"
    But all failed.

    Any help on this one?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. Replies: 3
    Last Post: 05-03-2003, 12:04 PM

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