ms vc++ header file problem

This is a discussion on ms vc++ header file problem within the C++ Programming forums, part of the General Programming Boards category; my header file wont compile..it is saying something is with the the function volume..."Box.obj : error LNK2005: "public: double __thiscall ...

  1. #1
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196

    ms vc++ header file problem

    my header file wont compile..it is saying something is with the the function volume..."Box.obj : error LNK2005: "public: double __thiscall CBox::Volume(void)const " (?Volume@CBox@@QBENXZ) already defined in Ex9_08.obj
    Debug/Ex9_08.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe."

    here is the code

    Code:
    // Box.h: interface for the CBox class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #if !defined(AFX_BOX_H__FC3564E5_37CD_11D7_AB37_00A0CC585627__INCLUDED_)
    #define AFX_BOX_H__FC3564E5_37CD_11D7_AB37_00A0CC585627__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    class CBox  
    {
    public:
    	double GetHeight() const { return m_Height; }
    	double GetBreadth() const { return m_Breadth; }
    	double GetLength() const { return m_Length; }
    	double Volume() const;
    
    	CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0);
    	virtual ~CBox();
    
    private:
    	double m_Height;
    	double m_Breadth;
    	double m_Length;
    };
    
    double CBox::Volume() const
    {
    	return m_Breadth*m_Height*m_Length;
    }
    
    #endif // !defined(AFX_BOX_H__FC3564E5_37CD_11D7_AB37_00A0CC585627__INCLUDED_)
    help is appreciated....
    nextus, the samurai warrior

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I see you are writing functions in your header file. CBox::Volume() should go into a cpp file.

  3. #3
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Usually you donīt compile header-files. They only serve as a interface (for the users of yourīs lib).

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    so i am not suppose to write any functions in the header file...just only the declarations....then what about inline functions...do i write that in the body of class definition?

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    Inlines stay in the header, but inside the class declaration.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. Problem with my file opener
    By kzar in forum C Programming
    Replies: 7
    Last Post: 04-20-2005, 04:20 PM
  4. Graphics header file problem
    By Senkoma in forum C++ Programming
    Replies: 1
    Last Post: 09-04-2001, 05:26 PM

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