I'm getting a linker error?

This is a discussion on I'm getting a linker error? within the C++ Programming forums, part of the General Programming Boards category; Error 1 error LNK2019: unresolved external symbol "public: __thiscall Fraction::Fraction(int,int)" (??0Fraction@@QAE@HH@Z) referenced in function "public: class Fraction __thiscall Fraction::Add(class Fraction,class ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    36

    I'm getting a linker error?

    Error 1 error LNK2019: unresolved external symbol "public: __thiscall Fraction::Fraction(int,int)" (??0Fraction@@QAE@HH@Z) referenced in function "public: class Fraction __thiscall Fraction::Add(class Fraction,class Fraction)" (?Add@Fraction@@QAE?AV1@V1@0@Z) C:\Users\Jesse\Desktop\C++ II\Chapter_15_Exercise_1\Chapter_15_Exercise_1\Cha pter_15_Exercise_1.obj Chapter_15_Exercise_1

    Any idea how to fix this? I can't figure out for the life of me how to fix it?

    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    #pragma once
    
    class Fraction
    {
    public:
    	Fraction (int numer = 1, int denom = 1);
    	~Fraction()
    	{ }
    
    	Fraction Add ( Fraction left_frac, Fraction right_frac);
    	Fraction Subtract ( Fraction left_frac, Fraction right_frac);
    	Fraction Multiply ( Fraction left_frac, Fraction right_frac);
    	Fraction Divide ( Fraction left_frack, Fraction right_frac);
    	void Display ();
    	void SetNumer (int numer);
    	void SetDenom( int numer);
    	int GetNumer();
    	int GetDenom();
    
    
    private:
    	int m_numer;
    	int m_denom;
    	void Reduce();
    };
    
    Fraction Fraction::Add(Fraction left_frac, Fraction right_frac)
    {
    	Fraction New_Frac;
    
    	New_Frac.SetDenom( left_frac.m_denom * right_frac.m_denom );
    	New_Frac.SetNumer( ( left_frac.m_denom * right_frac.m_numer ) + ( right_frac.m_denom * left_frac.m_numer ) );
    
    	return New_Frac;
    }
    
    Fraction Fraction::Subtract(Fraction left_frac, Fraction right_frac)
    {
    	Fraction New_Frac;
    
    	New_Frac.SetDenom( left_frac.m_denom * right_frac.m_denom );
    	New_Frac.SetNumer( (right_frac.m_denom * left_frac.m_numer) - (left_frac.m_denom * right_frac.m_numer) );
    
    	return New_Frac;
    }
    
    Fraction Fraction::Multiply(Fraction left_frac, Fraction right_frac)
    {
    	Fraction New_Frac;
    
    	New_Frac.SetNumer( left_frac.m_numer * right_frac.m_numer );
    	New_Frac.SetDenom( left_frac.m_denom * right_frac.m_denom );
    
    	return New_Frac;
    }
    
    Fraction Fraction::Divide(Fraction left_frac, Fraction right_frac)
    {
    	Fraction New_Frac;
    
    	New_Frac.SetNumer( left_frac.m_numer * right_frac.m_denom );
    	New_Frac.SetDenom( left_frac.m_denom * right_frac.m_numer );
    
    	return New_Frac;
    }
    
    void Fraction::Display()
    {
    	cout << m_numer << " / " << m_denom << endl;
    }
    
    void Fraction::SetNumer( int number)
    {
    	m_numer = number;
    }
    
    void Fraction::SetDenom( int number)
    {
    	m_denom = number;
    }
    
    int Fraction::GetNumer()
    {
    	return m_numer;
    }
    
    int Fraction::GetDenom()
    {
    	return m_denom;
    }
    
    
    int main()
    {
    	//Fraction f1( 1, 2),
    	//		 f2( 3, 4),
    	//		 f3;
    
    	//f3.Multiply(f1, f2);
    
    	//f1.Display();
    	//cout << " * ";
    	//f2.Display();
    	//cout << " = ";
    	//f3.Display();
    
    	return 0;
    }

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    You need to write your constructor:

    Code:
    Fraction (int numer = 1, int denom = 1);
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,351
    it's because you never actually define Fraction::Fraction(int, int). you only declare it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker error
    By black_spot1984 in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2008, 09:30 AM
  2. Linker error in C
    By walataza in forum C Programming
    Replies: 17
    Last Post: 03-12-2008, 07:03 PM
  3. linker error
    By fighter92 in forum C++ Programming
    Replies: 5
    Last Post: 08-08-2006, 12:45 PM
  4. [Linker error]
    By Overlord in forum C++ Programming
    Replies: 3
    Last Post: 07-29-2006, 05:44 AM
  5. help with linker error
    By wolf in forum C Programming
    Replies: 8
    Last Post: 08-11-2004, 01:34 AM

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