Newbie Question: My class

This is a discussion on Newbie Question: My class within the C++ Programming forums, part of the General Programming Boards category; Can someone please correct this for me and tell me what I did wrong? I don't really have such a ...

  1. #1
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40

    Newbie Question: My class

    Can someone please correct this for me and tell me what I did wrong? I don't really have such a firm understanding of classes. Any help is appreciated.
    TIA

    #include <iostream.h>

    class Camera
    {
    public:
    Camera();

    void PositionCamera(float PositionX, float PositionY, float PositionZ);

    private:
    float PositionX1;
    float PositionY1;
    float PositionZ1;
    };

    void Camera::PositionCamera(float PositionX, float PositionY, float PositionZ)
    {
    PositionX1 = PositionX;
    PositionY1 = PositionY;
    PositionZ1 = PositionZ;
    }


    void main()
    {
    Camera.PositionCamera(12,16,17);
    }

  2. #2
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    you need to instantiate the object.
    Code:
    int main() {
       Camera camera1;
       camera1.PositionCamera(12,16,17);
    
       return 0;
    }
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  3. #3
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40

    Compiler Maybe

    Nah... Still didn't work...
    Got the error

    rar.obj : error LNK2001: unresolved external symbol "public: __thiscall Camera::Camera(void)" (??0Camera@@QAE@XZ)
    Debug/rar.exe : fatal error LNK1120: 1 unresolved externals

    I was thinking that maybe its my Compiler (Visual C++ 6.0). However when it comes to just clicking the 'Compile' button no errors occur, it's only when i click on Build that I have trouble.
    Is there any needed library for Classes?

    Thanks eth0

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Your compiler expects a default constructor to be defined since you specified one should exist as a member of your class:

    Code:
    Camera::Camera()
    {
        // Do stuff here, initialize private members to 0.0 maybe?
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40
    Yep. It worked.
    Thanks hk_mp5kpdw and Eth0.

  6. #6
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by jimboob
    Yep. It worked.
    Thanks hk_mp5kpdw and Eth0.
    Sorry, I missed the fact that you had declared a constructor in your class.

    the error it was pulling up related to that fact. Broken down slightly:

    public: Camera::Camera(void) <--this is your constructor
    LNK1120: 1 unresolved externals <-- can't find the method


    You could of course pull out the constructor decleration from your class.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

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, 08:18 PM
  2. A question about class members and constructors
    By Megidolaon in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2009, 02:01 PM
  3. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  4. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 09:45 AM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM

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