Skip to main content
GameDev.net gamedev.net
🔒 Locked

Class On Freestore

Started by Mat1515 May 1, 2004 at 6:10 AM 11 replies 900+ views
Original Post
Mat1515
Mat1515
Why am i getting these errors? Look at posts below [edited by - Mat1515 on May 1, 2004 12:58:07 PM]
Ut o not me again:) lol
Goldfish
Goldfish
Why are you creating two CCamera instances? If you don''t delete the first one before creating the second, you''ll get a memory leak.
2 + 2 = 5 for extremely large values of 2
Mat1515
Mat1515

CCamera * g_Camera; //our camera!

g_Camera = new CCamera;



--------------------Configuration: Drag Race 2 - Win32 Debug--------------------
Compiling...
Main.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Drag Race 7\Main.cpp(30) : error C2501: ''g_Camera'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\Drag Race 7\Main.cpp(30) : error C2040: ''g_Camera'' : ''int'' differs in levels of indirection from ''class CCamera *''
C:\Program Files\Microsoft Visual Studio\MyProjects\Drag Race 7\Main.cpp(30) : error C2440: ''initializing'' : cannot convert from ''class CCamera *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

Drag Race 2.exe - 3 error(s), 0 warning(s)
Ut o not me again:) lol
Mat1515
Mat1515
bump
Ut o not me again:) lol
antareus
antareus
quote:
c:\program files\microsoft visual studio\myprojects\drag race 7\main.cpp(30) : error C2501: ''g_Camera'' : missing storage-class or type specifiers

Usually a dead giveaway the type (CCamera) is not working correctly. Did you forget to include the header?

quote:
c:\program files\microsoft visual studio\myprojects\drag race 7\main.cpp(30) : error C2040: ''g_Camera'' : ''int'' differs in levels of indirection from ''class CCamera *''

VC6 naively assumes it to be an integer type if it can''t figure out the type, so this only corroborates my theory.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Mat1515
Mat1515
Yes i do have my header included

HEADER!!!

#ifndef _CAMERA_H
#define _CAMERA_H

//***********************************************CAMERA CLASS*****************//

//VECTOR CLASS For Camera Movement Only

class CVector3 {
public: //Public Access

CVector3() {}
CVector3(float X, float Y, float Z) { //Class Constructor

x = X; y = Y; z = Z;} //Initiante to Starting Values

CVector3 operator+(CVector3 vVector){ //Overloaded + operator

return CVector3(vVector.x + x, vVector.y + y, vVector.z + z);}
CVector3 operator-(CVector3 vVector){ //Overloaded - operator

return CVector3(x - vVector.x, y - vVector.y, z - vVector.z);}
CVector3 operator*(float num){ //Overloaded * operator

return CVector3(x * num, y * num, z * num);}
CVector3 operator/(float num){ //Overloaded / operator

return CVector3(x / num, y / num, z / num);}
float x, y, z;
};

//CAMERA CLASS prototype

class CCamera{
public:
CVector3 m_vPosition; //Camera Position

CVector3 m_vView; //Camera View

CVector3 m_vUpVector; //Up Direction

//m = member Variables

//Camera Constructor

CCamera();
void RotateView(float angle, float x, float y, float z);
//Rotates Camera on someangle

void PositionCamera(float positionX,float positionY,float positionZ,
float viewX,float viewY,float viewZ,
float upVectorX, float upVectorY, float upVectorZ);
//Puts Camera at Posistion looking at Something a Position

void MoveCamera(float speed); //Moves the camera up or down

void SetViewByMouse(); //Set the view by the mouse posistion

void Look(); //Sets the camera to look at something

};

extern CCamera *g_Camera; //Allows all source files to use this


#endif


MAIN!!! SNIPPTET

#pragma comment(lib, "opengl32.lib") //Open Gl stuff

#pragma comment(lib, "glu32.lib") //Open Gl stuff

#pragma comment(lib, "glaux.lib") //Open gl Stuff


#include "Globals.hpp" //Global Includes

#include "Models.h" //For models

#include "Camera.hpp" //Camera Stuff

#include "Render.hpp" //Drawing Stuff

#include "Physics.hpp" //Car stuff physics

#include "Particle.hpp" //Particle Stuff

#include "Timer.hpp" //Timer Stuff

#include "resource.h" //Windows and Dialoge Stuff


#define CameraSpeed 0.15f //Speed at which the floating camera moves

//**************************************WINDOWS STUFF*************************//

HWND hwnd = NULL; //handle to window

HMENU hMenu = NULL; //Handle to main window menu

HINSTANCE hInstance; //handle to instance of application

HDC hDC = NULL; //handle to Device Context

HGLRC hRC = NULL; //handle to Rendering Context;

RECT g_rRect;

//*******************************CLASS CREATIONG*****************************//

CCamera *g_Camera = NULL; //our camera!

g_Camera = new CCamera;

Ut o not me again:) lol
Jingo
Jingo
Move g_Camera = new CCamera; out of the global namespace and into a function. Or replace both lines with CCamera *g_Camera = new CCamera;
Mat1515
Mat1515
i moved it into my setup GL function but now i get this error after comiling


--------------------Configuration: Drag Race 2 - Win32 Debug--------------------
Compiling...
Main.cpp
Render.cpp
Linking...
Camera.obj : error LNK2001: unresolved external symbol "class CCamera g_Camera" (?g_Camera@@3VCCamera@@A)
Debug/Drag Race 2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Drag Race 2.exe - 2 error(s), 0 warning(s)
Ut o not me again:) lol
Mat1515
Mat1515
Yes
Ut o not me again:) lol
mattnewport
mattnewport
You need this in your header:
extern CCamera* g_Camera; // Declaration 

This in one of your .cpp files:
CCamera* g_Camera = NULL; // Definition 

And this in a function somewhere before you try and use g_Camera:
g_Camera = new CCamera; // Assignment / dynamic memory allocation 

You can''t allocate memory outside of a function and you can''t define a global variable inside a function which is why you need to put the definition and the assignment in different places.
Mat1515
Mat1515
I give up it''s not working
Ut o not me again:) lol

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.