Thread: unresolved external.

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148

    unresolved external.

    Hi,

    I've been trying some OOP and despite cutting the code right down to skeleton, I'm still receiving the same error.

    This is my header file:
    Code:
    class Shape
    {
    public:
    
    	Shape (int l=0, int h=0);
    private:
    
    	int length;
    	int height;
    
    protected:
    
    };

    And this is main.cpp:
    Code:
    #include <iostream>
    #include "vessel.h"
    
    using namespace std;
    
    int main()
    {
    
    	int x;
    	int y;
    
    	cout << "enter the heighe" << endl;
    	cin >> x;
    	cout << "enter he length" << endl;
    	cin >> y;
    
    	Shape square(x,y);
    
    
    	system ("PAUSE");
    	return 0;
    }
    I'm using Visual Studio 2005 and this is the full error being reported, find it a little hard to understand:

    Code:
    ------ Build started: Project: my project, Configuration: Debug Win32 ------
    Compiling...
    main.cpp
    Linking...
    main.obj : error LNK2019: unresolved external symbol "public: __thiscall Shape::Shape(int,int)" (??0Shape@@QAE@HH@Z) referenced in function _main
    C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\my project\Debug\my project.exe : fatal error LNK1120: 1 unresolved externals
    Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\my project\my project\Debug\BuildLog.htm"
    my project - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Unfortunately after removing a lot of the code and being this with left, as I mention the same error is still occurring.

    Really appreciate it if someone could tell me what I'm doing wrong.

    Thanks very much

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    I'm guessing you did not add Shape.cpp to your project. If you did, does it implement the ctor that takes two ints?
    Last edited by medievalelks; 03-25-2009 at 06:42 PM.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148
    Thanks medievalks

    I just have two files: ( I know vessel.h is a daft name for a 'shape' class)

    vessel.h
    main.cpp

    I'm unable to build the project, so cannot put a breakpoint to see if the constructor is working.

    That's Every piece of code in the project.
    Last edited by Swerve; 03-25-2009 at 06:59 PM.

  4. #4
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Swerve View Post
    Hi,

    I've been trying some OOP and despite cutting the code right down to skeleton, I'm still receiving the same error.

    This is my header file:
    Code:
    class Shape
    {
    public:
    
    	Shape (int l=0, int h=0);
    private:
    
    	int length;
    	int height;
    
    protected:
    
    };
    try

    Code:
    #ifndef VESSEL_H
    #define VESSEL_H
    
    class Shape
    {
    public:
    
    	Shape (int l=0, int h=0);
    private:
    
    	int length;
    	int height;
    
    protected:
    
    };
    
    #endif
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #5
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148
    Thanks buddy but it still give the exact same error.

    I have no idea, I've took a screen shot.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Does it compile if you change your Shape class to:
    Code:
    class Shape
    {
    public:
    
    	Shape (int l=0, int h=0) : length(l), height(h) {}
    private:
    
    	int length;
    	int height;
    
    protected:
    
    };

  7. #7
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148
    It certainly does bithub!!

    I was proper flipping out then.

    Couldn't get a screen capture for you guys, then it was the wrong size, then it was still the wrong size, then my browser stopped responding.

    It works!

    thank you thank you thank you

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    And that's pretty much what medievalelks suggested in the first reply.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  5. Unresolved external symbols in OGL
    By Shadow12345 in forum Game Programming
    Replies: 4
    Last Post: 08-04-2002, 09:46 PM