Thread: Function outside the CLass

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    3

    Function outside the CLass

    Hi Everybody
    I have a project contains a Class with it's functions,
    but the functions of the class call another functions in .cpp and .h files which they are not included to the class
    when i compile it gives me undefined refrence for the functions outside the class so how i can include them since that i have large number of these functions
    Thanx

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    An undefined reference usually means that you have a declaration:

    Code:
    void do_something();
    but no definition:

    Code:
    void do_something()
    {
      std::cout << "Doing something!" << std::endl;
    }
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    Or in other words, the functions( aka the methods of the class ) aren't properly defined. Consider this example:
    MyClass.h
    Code:
    class MyClass
    {
        public:
            MyClass();
            ~MyClass();
    
            int getValue() const;
            void setValue(int newVal);
    
        private:
            int value;
    };
    MyClass.cpp
    Code:
    MyClass::MyClass(): value(0) {}
    MyClass::~MyClass() {}
    
    int MyClass::getValue() const { return value; }
    void MyClass::setValue(int newVal) { value = newVal; }
    Devoted my life to programming...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It can also mean you did not compile all .cpp files.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    but the functions of the class call another functions in .cpp and .h files which they are not included to the class
    Make sure you include the proper .h files, make sure you compile all the relevant .cpp files and make sure that they're all being linked together as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 10-08-2015, 06:04 AM
  2. Member function from class as a friend in another class
    By thames in forum C++ Programming
    Replies: 18
    Last Post: 01-02-2013, 05:32 AM
  3. Derived class doesn't see base class function
    By ejubenville in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2009, 01:56 PM
  4. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
  5. Replies: 2
    Last Post: 04-06-2005, 07:25 AM

Tags for this Thread