Thread: class function declarations

  1. #1
    Registered User
    Join Date
    Mar 2002

    class function declarations

    I'm having trouble with where I write the actual implementation for my functions. If I include them within the class braces, I can instantiate a class object from another .cpp file fine. However, if I move them out of the classes braces and just leave the prototypes, I get linking errors. I can leave them outside of the braces only if I declare them all inline (like they were when they were in the braces).

    Here is my code:
    #include <iostream.h>
    #include <stdio.h>
    class MP3File {
            FILE * mp3file;
    	bool initialized;
    	int bitRate;	
            MP3File(FILE * file);
    	bool parseHeader();
    	bool hasBeenInitialized();
    	void printHeaderInformation();
    inline MP3File :: MP3File(){ initialized = false; }
    inline MP3File :: MP3File(FILE * file)
            mp3file = file;
    	initialized = true;
    inline bool MP3File :: parseHeader()
    	bitRate = 50;
    	return true;
    inline bool MP3File :: hasBeenInitialized()
    	return initialized;
    inline void MP3File :: printHeaderInformation()
    	cout << "Header information" << endl;
    	cout << "Bit Rate: " << bitRate << endl;
    How can I eliminate making them inline but still be allowed to instantiate an MP3File object from another cpp file?

    Thanks in advance.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Remove the inline keyword and in the other files where you call them, redeclare each function as extern.

    My best code is written with the delete key.

  3. #3
    Would it look like :

           extern "C++"{
                    MP3File :: MP3File(FILE * file)


  4. #4
    Registered User
    Join Date
    Mar 2002
    Including the header file instead of the cpp file fixed it. Why does that make a difference to the linker?

  5. #5
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Because the compiler compiles together the.cpp's,
    You must inlcude the .h's

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM