Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:40:43+00:00 2026-06-16T03:40:43+00:00

Trying to compile the code below in Visual Studio 2010 gives me two errors

  • 0

Trying to compile the code below in Visual Studio 2010 gives me two errors about an unresolved external symbol. I’m pretty sure the issue is because I am using a function within a function but I don’t know specifically what I am doing incorrectly. The code looks ok to me.

#include <iostream>

using namespace std;

class fraction
{
  public:
    int gcd(int, int);
    void simplifyfraction();
  private:
    int integral, numerator, denominator;
};

int main(){
    return 0;
}

int gcd(int numerator, int denominator)
{
    if (denominator > numerator)
       return gcd(denominator, numerator);
    if (numerator == denominator)
       return numerator;
    if (numerator%denominator == 0)
       return denominator;
    return gcd(numerator, numerator-denominator);
}


void fraction::simplifyfraction()
{
    int mygcd;
    mygcd = gcd(numerator, denominator);
    numerator = numerator/mygcd;
    denominator = denominator/mygcd;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:40:45+00:00Added an answer on June 16, 2026 at 3:40 am

    The definition of gcd() is not qualified with the class name and is treated as a free standing function, a different function from the member function gcd() declared in the fraction class.

    As gcd() is invoked from fraction::simplifyfraction() the compiler searches for a function named gcd() and the first it finds is declared in the same scope as simplifyfraction(), namely fraction::gcd() which has no definition (it does not find the fully defined freestanding gcd() function). The linker subsequently complains that it has an unresolved symbol.

    To correct change to:

    int fraction::gcd(int numerator, int denominator)
    {
    }
    

    Just to note this could also have been fixed by not having gcd() as a member function (it does not access any member variables of fraction, all variables are passed as arguments) or the invocation of gcd() in fraction::simplifyfraction() could be changed to:

    mygcd = ::gcd(numerator, denominator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile the code in Visual Studio (2008) and g++. In vs2008
I get the following errors when trying to compile the below code using g++.
My code below won't compile. What am i doing wrong? I'm basically trying to
I'm trying to compile someone else's project, and I'm getting about 850 errors all
i'm trying to port code that compiles ok with visual studio and on linux
I'm trying to recompile older code in latest Visual Studio (2008) and code that
I am trying to compile an object file using the code below. //--Begin test.cpp
See the second bit of code below.. code doesn't compile. Am trying to figure
I got this error while trying to compile the below code. I would like
I'm trying to compile some code (below) using gcc 4.6.2 on OSX 10.6.5. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.