Pointer to function isn't exactly working

This is a discussion on Pointer to function isn't exactly working within the C++ Programming forums, part of the General Programming Boards category; I have this code Code: #include <iostream> #include <conio.h> using namespace std; double Area(double, double); int main() { double(*pArea)(double, double); ...

  1. #1
    Shadow12345
    Guest

    Pointer to function isn't exactly working

    I have this code
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    double Area(double, double);
    
    int main() {
    double(*pArea)(double, double);
    pArea = Area;
    double Length, Width;
    cout << "Enter the length and width of your rectangle " << endl;
    cin >> Length >> Width;
    	return 0;
    }
    And guess what, this code doesn't compile! Whaddya know. I get this error
    --------------------Configuration: pointertofunction - Win32 Debug--------------------
    Compiling...
    pointertofunction.cpp
    Linking...
    pointertofunction.obj : error LNK2001: unresolved external symbol "double __cdecl Area(double,double)" (?Area@@YANNN@Z)
    Debug/pointertofunction.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.


    I dont' have MSDN so I have no clue what this error means. It seems as though this code SHOULD work, please tell me why it in fact doesn't.
    thanks in advanced

    NEVERMIND, I DID NOT INCLUDE THE FUNCTION DEFINITION, IT COMPILES NOW, HOW SILLY OF ME

    I'VE FIXED EVERYTHING IT WORKS
    Last edited by Shadow12345; 06-21-2002 at 10:43 AM.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    That's because the linker can't find the code for the function Area.
    You must add this function to your code or link the correct library to your project.

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Talking

    Sorry, dindn't read your last line..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Replies: 5
    Last Post: 04-04-2009, 04:45 AM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

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