Advertisement

What's wrong with this class?

Started by August 21, 2002 06:40 AM
6 comments, last by Billy Lee 22 years, 4 months ago

  
// Draws the border around the playing area

#include <windows.h>
#include <gl/gl.h>
#include "border.h"

class Border
{

    private:

    // Screen dimensions

    float left_border   = -25.0f,
	  right_border  =  25.0f,
	  top_border	=  25.0f,
	  bottom_border = -25.0f;

    int top_face;										// Storage for 1st display list

    int side_face;										// Storage for 2nd display list


    public:

    // Construction/Destruction

    Border()
    {}

    ~Border()
    {}

    void BuildBorderLists()
    {
        ... (code) ...
    } // End of method BuildBorderLists



    void DrawBorder()
    {
        ... (code) ...
    } // End of method DrawBorder

}; 
  
I get error C2011: ''Border'' : ''class'' type redefinition .
Doubtless "border.h" already provides a definition of the class, and then you are defining it a second time. Don''t do that.
Advertisement
is something like: float left_border = -25.0f; realy working in the class definition? with which compiler?
My header file looks like this. Should I change the header file or the implementation file?


  #ifndef _border_h_#define _border_h_class Border  {	private:		// Screen dimensions		float left_border,			  right_border,			  top_border,			  bottom_border;		int top_face;							// Storage for 1st display list		int side_face;							// Storage for 2nd display list	public:		Border();		void BuildBorderLists();		void DrawBorder();		virtual ~Border();};#endif  


Botcher, it was working fine before I put it in a class. I''m using MSVC++ 6.0. Why do you ask?
you cant define what values the variables have when declaring the class. maybe the constructor becomes handy...

youre doing everything wrong!

when you decalre the class in .H you should fill the functions in .CPP dont fill the functions in the .H do it in the .CPP!
and when you wanna use the class:

Border Myborder;
Myborder.(a_var) = -25.0f

[edited by - pipo declown on August 21, 2002 8:11:34 AM]

[edited by - pipo declown on August 21, 2002 8:13:12 AM]
quote: Original post by Botcher
is something like: float left_border = -25.0f; realy working in the class definition? with which compiler?


No it''s not, I think this is the cpp file (notice it says: #include "border.h" ). The problem, as SabreMan said, is that BL seems to be defining his class a second time in the cpp file, thus the: ''class'' type redefinition .


----------------------------
I HATE COLLISION DETECTION!!
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
Advertisement
quote: Original post by Billy Lee
My header file looks like this. Should I change the header file or the implementation file?

You should change the implementation file, which should only contain definitions for the member functions, not the whole class. Here's an example:

    // junk.h#ifndef junk_h_included#define junk_h_includedclass Junk{public:  Junk();  int getVal();private:  int val_;};#endif  



  // junk.cpp#include "junk.h"Junk::Junk() : val_(0){}int Junk::getVal(){  return val_;}    


[edited by - SabreMan on August 21, 2002 8:23:08 AM]
SabreMan, as usual, is right on the money.

Also, use your constuctor to set the values of your member variables.


  // this should all be in the CPP file.//default constructorvoid Border::Border(){   left_border   = -25.0f;   right_border  =  25.0f;   top_border	 =  25.0f;   bottom_border = -25.0f;}// Customized constructor so someone can create a shape other than a square if they desire (ie: a rectangle)void Border::Border( float left, float right, float top, float bottom ){   left_border   = left;   right_border  = right;   top_border	 = top;   bottom_border = bottom;}// one of your member functionsvoid Border::BuildBorderLists(/*any instantiation vars*/){       ... (code) ...} // End of method BuildBorderLists  

{{crosses fingers and hopes everything is correct}}
- Advice, eh? Well, besides working on your swing...you know, besides that...I'd have to think.

This topic is closed to new replies.

Advertisement