Thread: Unresolved External

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    12

    Unresolved External

    Hey everyone, this is my first post so hopefully someone can help me. I've tried almost everything with this code and nothing's been working. Technically it is homework, but the point of the assignment was to find and fix errors, and trust me it was a lot uglier than this before i started on it :P. So I'm just wondering if I'm completely blind on this one or if it's a legitimate problem. Here's the code:
    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    
    class Circle
    {
    	public:
    		int radius;
    		void printArea();
    		void printDiameter();
    };
    
    double radius;
    void main()
    {
       void printArea(Circle);
       void printDiameter(Circle);
       Circle aBigCircle, aLittleCircle;
       aBigCircle.radius = 50;
       aLittleCircle.radius = 4;
       printArea(aBigCircle);
       printDiameter(aBigCircle);
       printArea(aLittleCircle);
       printDiameter(aLittleCircle);
    
       std::cin.clear();
       std::cin.ignore();
       getchar();
    }
    
    void Circle::printArea()
     {
    	double area;
        area = radius * radius * 3.14159;
        cout<<"A circle with radius "<<radius<<" has an area of "<<area<<endl;
     }
    void Circle::printDiameter()
    {
       double diam;
       diam = radius * 2;
       cout<<"A circle with radius "<<radius<<" has a diameter of "<<diam<<endl;
    }
    And the following is the build message:

    1>------ Build started: Project: Lab 4, Configuration: Debug Win32 ------
    1>Build started 04/02/2011 2:06:57 PM.
    1>InitializeBuildStatus:
    1> Touching "Debug\Lab 4.unsuccessfulbuild".
    1>ClCompile:
    1> asdf.cpp
    1>Link:
    1> LINK : C:\Users\-------\Documents\Visual Studio 2010\Projects\Lab 4\Debug\Lab 4.exe not found or not built by the last incremental link; performing full link
    1>asdf.obj : error LNK2019: unresolved external symbol "void __cdecl printDiameter(class Circle)" (?printDiameter@@YAXVCircle@@@Z) referenced in function _main
    1>asdf.obj : error LNK2019: unresolved external symbol "void __cdecl printArea(class Circle)" (?printArea@@YAXVCircle@@@Z) referenced in function _main
    1>C:\Users\-------\Documents\Visual Studio 2010\Projects\Lab 4\Debug\Lab 4.exe : fatal error LNK1120: 2 unresolved externals
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:02.61
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Seriously, any help would be fantastic. Also, this isn't a last resort kind of thing, it's not like it's due tomorrow. I've been working on it for 3 days and I'm dead stuck. Thanks for any future help

    Adam

  2. #2
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Oh, sorry I forgot to mention, it's C++ using Visual Studio 2010.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    void printArea(Circle);
    void printDiameter(Circle);
    etc..the functions you have supposedly declared within main do not match with those you have declared and defined for the class. So the compiler takes them to be externs.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You've written class methods, so you need to invoke them as class methods.

    printArea(aBigCircle);

    becomes

    aBigCircle.printArea();
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    12
    Awesome help guys, thanks. Final code:
    Code:
    // Debug 4-4
    // uses Circle class
    #include<iostream>
    #include<conio.h>
    using namespace std;
    
    class Circle
    {
    	public:
    		int radius;
    		void printArea();
    		void printDiameter();
    };
    
    double radius;
    void main()
    {
       void printArea();
       void printDiameter();
       Circle aBigCircle, aLittleCircle;
       aBigCircle.radius = 50;
       aLittleCircle.radius = 4;
       aBigCircle.printArea();
       aBigCircle.printDiameter();
       aLittleCircle.printArea();
       aLittleCircle.printDiameter();
    
       std::cin.clear();
       std::cin.ignore();
       getchar();
    }
    
    void Circle::printArea()
     {
    	double area;
        area = radius * radius * 3.14159;
        cout<<"A circle with radius "<<radius<<" has an area of "<<area<<endl;
     }
    void Circle::printDiameter()
    {
       double diam;
       diam = radius * 2;
       cout<<"A circle with radius "<<radius<<" has a diameter of "<<diam<<endl;
    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Now all you need to do is drop the conio.h include, remove the global variable and make main return an int.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testpad for itoa()
    By frktons in forum C Programming
    Replies: 92
    Last Post: 07-19-2010, 03:05 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM