• Create Account

## Why is my code giving me Error C2027 "use of an undefined type"

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1littletray26  Members

284
Like
0Likes
Like

Posted 26 October 2012 - 02:18 AM

Hey GameDev

I'm trying to make a 2D Camera class but it's giving me the aforementioned error, "Error C2027 "use of an undefined type 'Camera'". Any help with this one?

//Camera header
#include "Main.h"
struct Camera
{
public:
static D3DXVECTOR3 TransformVector3(D3DXVECTOR3 in);
static void InitializeCamera(RECT camSize, RECT wrldSize, D3DXVECTOR2 cameraPos);
static void UpdateCamera();
private:
static D3DXVECTOR2 cameraPosition;
static RECT cameraSize;
static RECT worldSize;
};
void Camera::InitializeCamera(RECT camSize, RECT wrldSize, D3DXVECTOR2 cameraPos)
{
cameraSize = camSize;
worldSize = wrldSize;
cameraPosition = cameraPos;
}
void Camera::UpdateCamera()
{
if (GetAsyncKeyState(0x41))
cameraPosition.x -= 10;
else
if (GetAsyncKeyState(0x44))
cameraPosition.x += 10;
if (GetAsyncKeyState(0x53))
cameraPosition.y -= 10;
else
if (GetAsyncKeyState(0x57))
cameraPosition.y += 10;
if (cameraPosition.x < worldSize.left)
cameraPosition.x = worldSize.left;
else
if (cameraPosition.x > worldSize.right)
cameraPosition.x = worldSize.right;
if (cameraPosition.y < worldSize.top)
cameraPosition.y = worldSize.top;
else
if (cameraPosition.y > worldSize.bottom)
cameraPosition.y = worldSize.bottom;
}
D3DXVECTOR3 Camera::TransformVector3(D3DXVECTOR3 in)
{
return D3DXVECTOR3((in.x - cameraPosition.x), (in.y - cameraPosition.y), (in.z));
}


Edited by littletray26, 26 October 2012 - 02:22 AM.

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #2BitMaster  Members

8647
Like
0Likes
Like

Posted 26 October 2012 - 02:22 AM

For the future, it would be helpful to say where exactly the error occurs.

The error happens whenever you use a type which has been just forward declared in a situation where the compiler needs to know more about it. For example:
// forward declarations
class MyType;

// further on
MyType* myPointer; // this is fine, the compiler does not need to know anything about MyType except that it exists
MyType myInstance; // this cannot work, the compiler does not even know how big the type is


### #3littletray26  Members

284
Like
0Likes
Like

Posted 26 October 2012 - 02:26 AM

Sorry, all it said was "Error 6 error C2027: use of undefined type 'Camera' line 16 coloumn 1 ZombieGame

Okay, but I didn't forward declare my Camera class?
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #4littletray26  Members

284
Like
0Likes
Like

Posted 26 October 2012 - 02:33 AM

Don't worry, I solved the problem. I was able to fix it by adding

#ifndef CAMERA
#define CAMERA

//rest of code

#endif


Seems I had overlooked the fact that the class would be redefined every time I included "Camera" and that must have caused the problem

Thanks

Edited by littletray26, 26 October 2012 - 02:35 AM.

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #5BitMaster  Members

8647
Like
0Likes
Like

Posted 26 October 2012 - 02:37 AM

I doubt it said, because MSVC generally spells 'column' correctly. ;) Please never paraphrase errors, always copy them exactly out of your compiler's output.

Also, I'm worried about the Error 6 in front of there. Are you absolutely certain the error is the actually first one the compiler encountered? Have you made sure the Error List is sorted in default order and not by something else?

### #6littletray26  Members

284
Like
0Likes
Like

Posted 26 October 2012 - 02:44 AM

I doubt it said, because MSVC generally spells 'column' correctly. ;) Please never paraphrase errors, always copy them exactly out of your compiler's output.

Also, I'm worried about the Error 6 in front of there. Are you absolutely certain the error is the actually first one the compiler encountered? Have you made sure the Error List is sorted in default order and not by something else?

If I had of copied it directly it would have looked like this "Error 6 error C2027: use of undefined type 'Camera' c:\users\jyhe\documents\visual studio 2010\projects\zombiegame\zombiegame\camera.h 19 1 ZombieGame"

I thought I'd make it make a bit more sense

It was the 6th error on the list, but it was the only one I was not familiar with
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #7BitMaster  Members

8647
Like
1Likes
Like

Posted 26 October 2012 - 02:48 AM

In C++, unless you know exactly what you are doing, always start with the first error and look at that error only. C++ is such a complex language, an error can produce such weird problems that all errors after that do not make any sense without having dealt with the initial problem first.

### #8littletray26  Members

284
Like
1Likes
Like

Posted 26 October 2012 - 02:51 AM

In C++, unless you know exactly what you are doing, always start with the first error and look at that error only. C++ is such a complex language, an error can produce such weird problems that all errors after that do not make any sense without having dealt with the initial problem first.

Yeah well the first error told me that Camera was being redefined but I made the mistake of ignoring it and trying to fix the one I thought most important first. As it turns out, by fixing the first error, I'd fixed the others too.

Lesson learned
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.