• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
littletray26

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

7 posts in this topic

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?

[CODE]
//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));
}
[/code] Edited by littletray26
0

Share this post


Link to post
Share on other sites
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:
[code]
// 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
[/code]
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
Don't worry, I solved the problem. I was able to fix it by adding

[code]
#ifndef CAMERA
#define CAMERA

//rest of code

#endif
[/code]

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 [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by littletray26
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
[quote name='BitMaster' timestamp='1351240646' post='4994073']
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?
[/quote]

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 :P

It was the 6th error on the list, but it was the only one I was not familiar with :)
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
[quote name='BitMaster' timestamp='1351241333' post='4994075']
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.
[/quote]

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 :)
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0