|
MSVC cannot find my Rectangle class |
OmegaWarrior
Member #15,041
April 2013
|
I'm trying to create a game in C++ using Allegro, and I created a simple Rectangle class, but it appears to somehow be out of scope in my main program, I have: stdafx.h
1#ifndef __STDAFX_H
2#define __STDAFX_H
3
4#include <iostream>
5#include <stdio.h>
6#include <allegro5\allegro.h>
7#include <allegro5\allegro_font.h>
8#include <allegro5\allegro_ttf.h>
9#include <allegro5\allegro_primitives.h>
10#include <allegro5\allegro_image.h>
11#include <math.h>
12#include <string>
13#include <list>
14
15#endif //ifndef __STDAFX_H
Vector2.h
1#include "stdafx.h"
2
3#ifndef __VECTOR2_H
4#define __VECTOR2_H
5
6using namespace std;
7
8struct Vector2
9{
10public:
11 float X,Y;
12 Vector2() { }
13 Vector2(const Vector2&) { }
14 Vector2(const float& x, const float& y) : X(x), Y(y) { }
15 ~Vector2( ) { }
16 Vector2 operator+(const Vector2& v);
17 Vector2 operator-(const Vector2& v);
18};
19
20#endif
Rectangle.h
1#include "Vector2.h"
2
3#ifndef __RECTANGLE_H_
4#define __RECTANGLE_H_
5
6using namespace std;
7
8class Rectangle
9{
10public:
11 Rectangle() { }
12 Rectangle(const Rectangle& r);
13 Rectangle(const float& x,const float& y,const float& h,const float& w);
14 ~Rectangle() { }
15 void SetPosX(const float& x);
16 void SetPosY(const float& y);
17 void SetHeight(const float& h);
18 void SetWidth(const float& w);
19
20 bool Intersects(const Rectangle* r);
21
22 Vector2* GetIntersection(const Rectangle* r);
23
24 float x,y,w,h;
25};
26
27
28#endif
Main.cpp
1#include "stdafx.h"
2#include "Rectangle.h"
3
4using namespace std;
5
6// Other functions...
147void myDraw(ALLEGRO_BITMAP* texture, Rectangle source, Rectangle dest, ALLEGRO_COLOR tint, Vector2 scale, float angle, int flags) //<-- This is where the error message points
148{
149 al_draw_tinted_scaled_rotated_bitmap_region(texture,
150 source.x, source.y, source.w, source.h,
151 tint,
152 dest.x, dest.x, dest.w, dest.h,
153 scale.X, scale.Y,
154 angle, flags);
155
156 return;
157}
Help? The specific error I'm getting is: Also relevant: 41 IntelliSense: function "Rectangle" is not a type name main.cpp 147 |
atlasc1
Member #15,020
March 2013
|
I've copied and pasted the code you have supplied into MSVS2012 Ultimate and it compiles fine. There may be something causing a problem somewhere else. On another note, it's generally a bad idea to use double underscores in include guards (e.g., __VECTOR2_H). The use of two underscores in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
|
Jeff Bernard
Member #6,698
December 2005
|
OmegaWarrior said: Also relevant: 41 IntelliSense: function "Rectangle" is not a type name main.cpp 147 Somewhere Rectangle() is being included in your project. I'm guess allegro_primitives.h somewhere along the road #include <wingdi.h>? Edit: It's allegro.h that's the culprit. -- |
OmegaWarrior
Member #15,041
April 2013
|
Thanks, I renamed everything Rectangle in my code to MyRect and it compiled successfully (I really hate it when it's something stupid and simple like that). Now that that's settled, I just have to remember what I was doing when my world froze. Thanks! |
|