Thread: Question Regarding EzWindows and Classes

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    3

    Question Regarding EzWindows and Classes

    Hi this is my first post to this board and I come here for help. I am currently taking C++ online in college as it is required for my degree and it was not offered in class room. I was given a homework assignment that myself and the rest of the students have not been able to figure out. I have written the code and have tried many different things but for some reason cant get the code to run without any errors. I was wondering if someone could look at my code and tell me what I am doing wrong. I have included the Ezwinvc50.lib in in my library files and in the project itself and included the ezwin.h include file in the projects.

    The Assignment is:

    Use the following declaration for a square object.

    Code:
    class Square {
    public: 
    	Square(SimpleWindow &W);
    	void Draw();
    	void SetColor(const color &Color);
    	void SetPosition(float XCoord, float YCoord);
    	void SetSize(float Length);
    private:
    	color Color;
    	float XCenter;
    	float YCenter;
    	float SideLength;
    	SimpleWindow &Window;
    };
    Write a code fragment that defines and draws a square object with 1.5-centimeter sides called GreenSquare that is displayed on the Window Sample. Position GreenSquare's Center 3.5 centimeters from the left edge and 2.5 centimetters from the top edge of the window. GreenSquare Should be green.

    Here is my code as follows.

    Code:
    #include <iostream>
    using namespace std;
    #include "I:\GreenSquare\EzWin\ezwin.h"
    
    SimpleWindow W("Sample", 8.0, 8.0);
    
    class Square {
    public: 
    	Square(SimpleWindow &W);
    	void Draw();
    	void SetColor(const color &Color);
    	void SetPosition(float XCoord, float YCoord);
    	void SetSize(float Length);
    private:
    	color Color;
    	float XCenter;
    	float YCenter;
    	float SideLength;
    	SimpleWindow &Window;
    };
    
    int ApiMain() {
    	W.Open();
    	Square GreenSquare(Window, Green, 3.5, 2.5, 1.5);
    	GreenSquare.Draw();
    	return 0;
    }
    The following error message I am getting now is

    i:\greensquare\greensquare\greensquare.cpp(34) : error C2065: 'Window' : undeclared identifier

    I am no C++ expert as I am still in the learning stages.

    If you need the EZWin files to test my program they can be found here

    http://cairns.it.jcu.edu.au/Subjects...es/ezwinfiles/

    Thanks in Advance for any help

    On a side note I know why they didnt teach this as an in classroom class. Me and another student met with the teacher yesterday to try and get some help and he was unable to help us figure out what was causing the errors and didnt know anything about the EZWindows which was part of the assignment and chapter we were studying!
    Last edited by Stryker30; 04-01-2006 at 09:47 AM.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    int ApiMain() {
    	W.Open();
    	Square GreenSquare(Window, Green, 3.5, 2.5, 1.5);
    	GreenSquare.Draw();
    	return 0;
    }
    What's 'Window'? Could you have intended 'W' which is your global SimpleWindow instance?

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    I made some modifications to my code. I had noticed the naming conventions W and Window when comparing it to a sample program written. I also included in the original Square class the declarations so I could refer to them in my code. I dont want anyone to do the work for me I just want to be pointed in the rigfht direction as to what I might be doing wrong! Thanks for the first reply!

    Code:
    #include <iostream>
    using namespace std;
    #include "I:\GreenSquare\EzWin\ezwin.h"
    
    class Square {
    public: 
    	Square(SimpleWindow &W, const color, float XCenter, float YCenter, float SideLength);
    	void Draw(); 
    	void SetColor(const color &Color);
    	void SetPosition(float XCoord, float YCoord);
    	void SetSize(float Length);
    private:
    	color Color;
    	float XCenter;
    	float YCenter;
    	float SideLength;
    	SimpleWindow &Window;
    };
    
    SimpleWindow W("Sample", 8.0, 8.0);
    
    int ApiMain() {
    	W.Open();
    	Square GreenSquare(W, Green, 3.5, 2.5, 1.5);
    	GreenSquare.Draw();
    	return 0;
    };
    now I am getting the following errors

    Code:
    GreenSquare.obj : error LNK2001: unresolved external symbol "public: void __thiscall Square::Draw(void)" (?Draw@Square@@QAEXXZ)
    
    GreenSquare.obj : error LNK2001: unresolved external symbol "public: __thiscall Square::Square(class SimpleWindow &,enum color,float,float,float)" (??0Square@@QAE@AAVSimpleWindow@@W4color@@MMM@Z)
    
    Debug/GreenSquare.exe : fatal error LNK1120: 2 unresolved externals

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Well, now you use the objects constructor making the GreenSquare and call Square::Square(..), and also the Square::Draw(void) method. But I don't think you actually coded those functions yet. To implement your classes methods, you can do a few things. Firstly, you could implement them inline inside your class definition like so:

    Code:
    class Square {
    public: 
    	Square(SimpleWindow &W, const color, float XCenter, float YCenter, float SideLength);
    	void Draw()
    	{
    		std::cout << "We're drawing me now" << std::endl;
    	}
    	void SetColor(const color &Color);
    	void SetPosition(float XCoord, float YCoord);
    	void SetSize(float Length);
    private:
    	color Color;
    	float XCenter;
    	float YCenter;
    	float SideLength;
    	SimpleWindow &Window;
    };
    Or like this:

    Code:
    class Square {
    public: 
    	Square(SimpleWindow &W, const color, float XCenter, float YCenter, float SideLength);
    	void Draw(); 
    	void SetColor(const color &Color);
    	void SetPosition(float XCoord, float YCoord);
    	void SetSize(float Length);
    private:
    	color Color;
    	float XCenter;
    	float YCenter;
    	float SideLength;
    	SimpleWindow &Window;
    };
    
    void Square::Draw()
    {
    	std::cout << "We're here" << std::endl;
    }

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    Ok I seee what we had to do on the Draw() Function and I am trying to figure out to deal with the Square Function. I am down to the following errors and am not sure how to deal with them.

    Code:
    GreenSquare.obj : error LNK2001: unresolved external symbol "public: __thiscall Square::Square(class SimpleWindow &,enum color,float,float,float)" (??0Square@@QAE@AAVSimpleWindow@@W4color@@MMM@Z)
    
    Debug/GreenSquare.exe : fatal error LNK1120: 1 unresolved externals

Popular pages Recent additions subscribe to a feed