Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2010
    Posts
    6

    Problem Debugging but Compiles okay?

    [CODE
    ]#include <iostream>
    using namespace std;

    void printString(char *m);

    void main()
    {

    printString("Colin");


    }
    [/CODE]

    Im going through the tutorials atm and was following the functions tutorial. I have run into a problem though when I try to debug.

    1>------ Build started: Project: colin, Configuration: Debug Win32 ------
    1>colin.obj : error LNK2019: unresolved external symbol "void __cdecl printString(char *)" (?printString@@YAXPAD@Z) referenced in function _main
    1>c:\users\bozothecat\documents\visual studio 2010\Projects\colin\Debug\colin.exe : fatal error LNK1120: 1 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    ** Im using Microsoft Visual Studios 2010 Express

  2. #2
    Join Date
    Nov 2008
    Location
    41° 28′ 56″ N, 81° 40′ 11″ W
    Posts
    2,399
    Here, fixed:

    Code:
    #include <iostream>
     using namespace std;
     
    void printString();
     
    void main()
     {
    	int quit;
    	printString();
    	cout << "Press <0> + <ENTER> to Quit to Windows:  ";
    	cin >> quit;
    
    }
    
    void printString()
    {
    	cout << "Colin" << endl;
    }
    PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, Corsair HX620W PSU, Corsair Vengeance 16GB (4x4GB) DDR3-1600, EVGA GTX 680 2GB GDDR5, 3D Vision Kit 2, LG 8x Blu-ray Burner, Intel X25-M SSD, 500GB+640GB WD Caviar Blacks, Win 7 Pro x64, DAS Pro K/B, MX518 Mouse, Logitech Z-2300 Speakers, Toshiba 32TL515U 32" 3DTV, Wacom Bamboo Fun Large Tablet.

  3. #3
    Join Date
    Aug 2010
    Posts
    76
    To kind of put what WedgeBob put into perspective, sorta. (since I'm still only a kind of beginner as well)

    You declare a method (don't know the actual term for that), and then you never define it. So even if it calls for that method it can't actually do anything, becasue it doesn't know what it's actually supposed to do. Think of it as like saying, that method is being stated to exist in that spot only when you put the semi-colon/terminator at the end of a declared method. However you still need to define what it does at some point in the code. You declare it like that though before the main function that way the compiler knows that somewhere it does exist.

    Secondly, for your argument you're using a pointer. You don't actually need a pointer whenever you use a char for an argument. Since in this case if you're simply wanting the argument to be what's displayed on the console, then you would say something like a normal char. Because you don't need to point to anything. Or need the address of anything.

    So basically what WB has done is declare the function that way Main function knows about it in advance, and then below Main, has defined it so that when called it prints out Collin onto the console.

    Also what he's done is that basically he's having it where the console won't close on you immediately. Because cin is waiting for the user input a value for the variable "quit" he created.

    I hope this was of some use for you. If not I apologize for rambling on so long.

  4. #4
    Join Date
    Nov 2008
    Location
    41° 28′ 56″ N, 81° 40′ 11″ W
    Posts
    2,399
    *Sigh* Maybe I may be stabbed for saying this, or maybe I may need to rewatch the VTM on pointers, but...

    I thought from what I understood, that C++ is very picky about how you declare pointers in your code. I believe you can only declare it once throughout the whole program code...and how you use that pointer variable can be quite tricky. Of course, the way I corrected the code without the pointer declaration made it more than safe to compile right out of the box without any error or warning. I could have heard wrong, but I fell asleep during half of the pointers video, so forgive me.

    (Please don't stab me in the IRC for this, Nelson, but...I guess that C# is more my forte, but C++ was what I learned first, obviously).
    PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, Corsair HX620W PSU, Corsair Vengeance 16GB (4x4GB) DDR3-1600, EVGA GTX 680 2GB GDDR5, 3D Vision Kit 2, LG 8x Blu-ray Burner, Intel X25-M SSD, 500GB+640GB WD Caviar Blacks, Win 7 Pro x64, DAS Pro K/B, MX518 Mouse, Logitech Z-2300 Speakers, Toshiba 32TL515U 32" 3DTV, Wacom Bamboo Fun Large Tablet.

  5. #5
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Quote Originally Posted by WedgeBob View Post
    I thought from what I understood, that C++ is very picky about how you declare pointers in your code. I believe you can only declare it once throughout the whole program code...and how you use that pointer variable can be quite tricky.
    um... no, not really. maybe you're confusing pointers with references (which behave roughly like a const-pointer)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •