C++ Multiple Static Functions With Same Name But Different Arguments [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
It appears as though I stumbled across something odd while trying to write my own wrapper for the freeglut api. Basically, I am writing my own little library to make using freeglut easier. One of the first things that I am doing is attempting to implement my own Color class which will be fed into "glClearColor". I am also having it so that you can enter the colors in manually; this means that I will have multiple static methods with the same name but different parameters/arguments. I tried to compile this afterwards but received an error that makes me think that the compiler cant decide which method to use—which is odd considering the two methods in question are still different. One takes a Color3 class and the other a Color4.
Here is some source:
GL.H
#pragma once
#include "Vector3.h"
#include "Color3.h"
#include "Color4.h"
#include <string>
class GL
{
public:
static void initializeGL(int argc, char* argv);
static void initializeDisplayMode(unsigned int displayMode);
static void initializeWindowSize(int width, int height);
static void createWindow(std::string title);
static void mainLoop();
static void translate(const Vector3 &location);
static void translate(float x, float y, float z);
static void rotate(double rotation, float x, float y, float z);
static void rotate(double rotation, const Vector3& axis);
static void color3(const Color3 &color);
static void color4(const Color4 &color);
static void begin();
static void end();
static void pushMatrix();
static void popMatrix();
static void enable(int enableCap);
static void viewport();
static void polygonMode();
static void matrixMode();
static void clearColor(const Color3 &color);
static void clearColor(float red, float green, float blue);
static void clearColor(float red, float green, float blue, float alpha);
static void clearColor(const Color4 &color);
static void vertex3(const Vector3 &location);
static void vertex3(float x, float y, float z);
static void loadIdentity();
static void perspective();
static void depthFunction();
};
GL.cpp
#include "GL.h"
#include "freeglut.h"
void GL::clearColor(const Color3 &color)
{
glClearColor(color.getRed,color.getGreen,color.getBlue, 1.0f);
}
void GL::clearColor(float red, float green, float blue)
{
glClearColor(red, green, blue, 1.0f);
}
void GL::clearColor(float red, float green, float blue, float alpha)
{
}
void GL::clearColor(const Color4 &color)
{
}
And here is my compiler error:
1>------ Build started: Project: GameEngineToolkit, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\main.cpp(47): error C2665: 'GL::clearColor' : none of the 4 overloads could convert all the argument types
1> c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.h(610): could be 'void GL::clearColor(const Color4 &)'
1> c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.h(607): or 'void GL::clearColor(const Color3 &)'
1> while trying to match the argument list '(Color3 *)'
1> GL.cpp
1>c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getRed': function call missing argument list; use '&Color3::getRed' to create a pointer to member
1>c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getGreen': function call missing argument list; use '&Color3::getGreen' to create a pointer to member
1>c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getBlue': function call missing argument list; use '&Color3::getBlue' to create a pointer to member
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
As you can see, it seems that the compiler cant decide between using the Color3 function or the color4 function; I don't understand why because it should be obvious which one to choose(the Color3 one is the one I am using in my main).
As per request, here is my Color3 class:
Color3.h
#pragma once
class Color3
{
public:
Color3();
Color3(float red, float green, float blue);
void setRed(float red);
void setGreen(float green);
void setBlue(float blue);
float getRed();
float getGreen();
float getBlue();
Color3 getColor();
~Color3();
private:
float red;
float green;
float blue;
};
Color3.cpp
#include "Color3.h"
Color3::Color3()
{
}
Color3::Color3(float red, float green, float blue)
{
setRed(red);
setGreen(green);
setBlue(blue);
}
Color3::~Color3()
{
}
float Color3::getRed()
{
return red;
}
float Color3::getGreen()
{
return green;
}
float Color3::getBlue()
{
return blue;
}
void Color3::setBlue(float blue)
{
this->blue = blue;
}
void Color3::setGreen(float green)
{
this->green = green;
}
void Color3::setRed(float red)
{
this->red = red;
}
Color3 Color3::getColor()
{
return *this;
}
The Solution:
Use pointers.
GL.cpp
#include "GL.h"
#include "freeglut.h"
void GL::clearColor(Color3* color)
{
glClearColor(color->getRed(),color->getGreen(),color->getBlue(), 1.0f);
}
void GL::clearColor(float red, float green, float blue)
{
glClearColor(red, green, blue, 1.0f);
}
void GL::clearColor(float red, float green, float blue, float alpha)
{
}
void GL::clearColor(Color4* color)
{
}
GL.H
#pragma once
#include "Vector3.h"
#include "Color3.h"
#include "Color4.h"
#include <string>
class GL
{
public:
static void initializeGL(int argc, char* argv);
static void initializeDisplayMode(unsigned int displayMode);
static void initializeWindowSize(int width, int height);
static void createWindow(std::string title);
static void mainLoop();
static void translate(const Vector3 &location);
static void translate(float x, float y, float z);
static void rotate(double rotation, float x, float y, float z);
static void rotate(double rotation, const Vector3& axis);
static void color3(const Color3 &color);
static void color4(const Color4 &color);
static void begin();
static void end();
static void pushMatrix();
static void popMatrix();
static void enable(int enableCap);
static void viewport();
static void polygonMode();
static void matrixMode();
static void clearColor(Color3* color); // Use pointers instead
static void clearColor(float red, float green, float blue);
static void clearColor(float red, float green, float blue, float alpha);
static void clearColor(Color4* color); // Same thing; no error. =P
static void vertex3(const Vector3 &location);
static void vertex3(float x, float y, float z);
static void loadIdentity();
static void perspective();
static void depthFunction();
};

Well first of all, you're passing a Color3 pointer into an overloaded function that takes two different references.
You have a range of options:
Don't pass a pointer (you have Color3 color in main(), don't pass &color, pass color)
De-reference the pointer to pass a reference (having a Color3* color in main(), pass *color not color)
Change the method or add one to accept a Color3 pointer. This is dumb and I don't advise it. But you can!
Also I know it's not a part of the question but it appears getRed, getGreen, and getBlue are methods that you should append () to.

Related

C++ Qualified name is not allowed in member declaration

I am following one of Fleeps old tutorials from 2012. I have encountered a speedbump, this error: qualified name is not allowed in member declaration.
I have tried changing the SDK, defining/declaring the class in the main.cpp file. None of this worked.
This is my header file i am encountering the error in.
#pragma once
#include <Windows.h>
#include "d3d9.h"
#include <ctime>
#include <iostream>
#define D3DHOOK_TEXTURES
#define MAX_MENU_ITEMS 6
#define WALLHACK 0
#define CUSTOM_CROSSHAIR 1
#define NO_RECOIL 2
#define UNLIM_AMMO 3
#define AUTO_FIRE 4
#define HIDE_MENU 5
class Hacks {
public:
int m_Stride;
void Hacks::CreateFont(IDirect3DDevice9 *d3dDevice, std::string choiceFont);
void Hacks::InitializeMenuItems();
void Hacks::DrawText(LPCSTR TextToDraw, int x, int y, D3DCOLOR Color);
void Hacks::DrawMenu(IDirect3DDevice9 *d3dDevice);
void Hacks::DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR Color, IDirect3DDevice9 *d3dDevice);
void Hacks::DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR Color, IDirect3DDevice9 *d3dDevice);
void Hacks::KeyboardInput();
LPDIRECT3DTEXTURE9 texRed;
LPDIRECT3DTEXTURE9 texGreen;
LPDIRECT3DTEXTURE9 texBlue;
LPDIRECT3DTEXTURE9 texWhite;
D3DVIEWPORT9 ViewPort;
LPD3DXFONT Font;
struct d3dMenuHack {
bool on;
std::string name;
};
d3dMenuHack hack[MAX_MENU_ITEMS];
};
The error is ocouring when i am declaring the "void Hacks::"... functions. Any suggestions?
Maybe nikau6's answer is not so clear at first sight because the code seems identical to the one in the OP.
So, the solution is to remove Hacks:: from all your declarations
While building a legacy Direct Show filter in Visual Studio 2019 I had to set Conformance Mode to No. This allows the code to not conform to the standard /permissive-
The above is poor practice as stated by several people. But with legacy code it's often the not appropriate(or possible) to make it follow best practices.
No qualified names to use in member declarations. Which compiler is used in your book ?
class Hacks {
public:
int m_Stride;
void CreateFont(IDirect3DDevice9 *d3dDevice, std::string choiceFont);
void InitializeMenuItems();
void DrawText(LPCSTR TextToDraw, int x, int y, D3DCOLOR Color);
void DrawMenu(IDirect3DDevice9 *d3dDevice);
void DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR Color, IDirect3DDevice9 *d3dDevice);
void DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR Color, IDirect3DDevice9 *d3dDevice);
void KeyboardInput();
LPDIRECT3DTEXTURE9 texRed;
LPDIRECT3DTEXTURE9 texGreen;
LPDIRECT3DTEXTURE9 texBlue;
LPDIRECT3DTEXTURE9 texWhite;
D3DVIEWPORT9 ViewPort;
LPD3DXFONT Font;
struct d3dMenuHack {
bool on;
std::string name;
};
d3dMenuHack hack[MAX_MENU_ITEMS];
};

C++ Direct2D - Linker error 2019 after moving sine files from my laptop

I wanted to move some code that I wrote, on my laptop, to my other PC. I didn't use Github or any other type of source control, I just simply copied the c++ files on to a USB drive and put them on my other PC.
And now I'm getting an error, for some reason, when I try to run the code?
The code is simply a class that uses direct2d to draw on a window.
This is what it looks like:
#pragma once
#include <Windows.h>
#include <d2d1.h>
#include <iostream>
#include "LinkedList.h"
class Graphics
{
private:
ID2D1Factory* pFactory;
ID2D1HwndRenderTarget* pRenderTarget;
ID2D1SolidColorBrush* pBrush;
RECT bounds;
float lineWidth = 5.0f;
LinkedList pointList;
public:
Graphics();
~Graphics();
void BeginDraw() { pRenderTarget->BeginDraw(); };
void EndDraw() { pRenderTarget->EndDraw(); };
void SetBrushColor(float r, float g, float b, float a);
void SetBrushColor(float r, float g, float b);
void SetLineWidth(float width);
RECT GetBounds();
void ClearScreen(float r, float g, float b, float a);
void ClearScreen(float r, float g, float b);
void FillCircle(float x, float y, float radius);
void DrawCircle(float x, float y, float radius);
void FillRect(float x, float y, float w, float h);
void DrawRect(float x, float y, float w, float h);
void MoveTo(float x, float y);
void LineTo(float x, float y);
void tester();
bool Init(HWND* pWindowHandle);
};
And the error I'm getting is this:
Error LNK2019 unresolved external symbol _D2D1CreateFactory#16 referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory##YAJW4D2D1_FACTORY_TYPE##ABU_GUID##PAPAX#Z) ffff c:\Users\sharkgaming\documents\visual studio 2015\Projects\ffff\ffff\Graphics.obj 1
At first I thought it was because I forgot to link to the d2d1.lib but even after doing that I'm still getting the error?
So, does anyone know why I'm getting the error and how to fix it?
Okay,
after googling around, for an hour or two, I found out that basically adding this:
#pragma comment(lib,"d2d1.lib")
would fix my problem.
But I have absolutely no idea why, since I already went in to the linker settings and added d2d1.lib to the additional library files?
EDIT: OMG I just figured it out.
I added the library to the x64 build settings not the x86. -_-

Error: invalid use of member in static member function

I have two classes, and this is the header of one of them:
#ifndef WRAPPER_HPP
#define WRAPPER_HPP
#include <SDL/SDL.h>
using namespace std;
class Wrapper
{
private:
//SDL_Surface *screen;
public:
static SDL_Surface *screen;
static void set_screen(SDL_Surface *_screen);
static void set_pixel(int x, int y, Uint8 color);
static void clear_screen(int r, int g, int b);
static SDL_Surface* load_image(char path[500]);
static void draw_image(SDL_Surface *img, int x, int y, int width, int height);
static void draw_line(int x1, int y1, int x2, int y2, Uint8 color);
};
#endif
I am calling Wrapper::set_screen(screen) from another file and I get this error:
In file included from /home/david/src/aships/src/Wrapper.cpp:6:0:
/home/david/src/aships/src/Wrapper.hpp: In static member function ‘static void Wrapper::set_screen(SDL_Surface*)’:
/home/david/src/aships/src/Wrapper.hpp:11:18: error: invalid use of member ‘Wrapper::screen’ in static member function
/home/david/src/aships/src/Wrapper.cpp:10:3: error: from this location
I also get a similar error for the definition of every single function on Wrapper.cpp, for example:
void Wrapper::set_pixel(int x, int y, Uint8 color)
{
/* Draws a pixel on the screen at (x, y) with color 'color' */
Uint8 *p;
p = (Uint8 *) screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
*p = color;
}
On compile:
/home/david/src/aships/src/Wrapper.hpp: In static member function ‘static void Wrapper::set_pixel(int, int, Uint8)’:
/home/david/src/aships/src/Wrapper.hpp:11:18: error: invalid use of member ‘Wrapper::screen’ in static member function
/home/david/src/aships/src/Wrapper.cpp:17:17: error: from this location
I know it's related to the class being static and thus the variable Wrapper.screen is not accessible or something, but I'm not sure of how to fix it. Any ideas?
You are using a static variable
static SDL_Surface *screen;
in your code.
In C++ when you declare a static variable in the .h (or .hpp) you are creating a variable that is general (static) to the class. Thus, to use it in another file you have to redeclare it (which I'm guessing you didn't) to create a variable in that file referencing the static one. In your case put this:
SDL_Surface* Wrapper::screen;
in the .cpp file.
I'm not sure the theory is well explained, but it works like that.
Your class and member (screen) are not static, which means they don't actually exist.
You can't access a non static member in a static function.
Try to make your data members to be static.
I'm not convinced that the code abstract you show us is an accurate characterization of your problem.
Your header should not include using namespace std; — it doesn't use or declare anything from the std namespace, and specifying using namespace std; is generally regarded as 'not a good idea', doubly so when it appears in a header file.
It also isn't clear that your header needs to include SDL/SDL.h. If the Uint8 type is easily isolated (not necessarily valid), then your header file can simply use a forward declaration of the SDL_Surface class. (Your implementation code will need to include SDL/SDL.h; but you should not burden the users of your wrapper class with unnecessary #include directives when simple forward declarations would suffice.)
This code is self-contained (does not need any headers), but more or less simulates what you could use, and it compiles OK:
#ifndef WRAPPER_HPP
#define WRAPPER_HPP
typedef unsigned char Uint8;
class SDL_Surface;
class Wrapper
{
public:
static SDL_Surface *screen;
static void set_screen(SDL_Surface *_screen);
static void set_pixel(int x, int y, Uint8 color);
static void clear_screen(int r, int g, int b);
static SDL_Surface *load_image(char path[500]);
static void draw_image(SDL_Surface *img, int x, int y, int width, int height);
static void draw_line(int x1, int y1, int x2, int y2, Uint8 color);
};
#endif
//#include <SDL/SDL.h>
typedef unsigned short Uint16;
class SDL_Surface
{
public:
Uint8 *pixels;
Uint16 pitch;
struct
{
Uint8 BytesPerPixel;
} *format;
};
// End of SDL/SDL.h
void Wrapper::set_pixel(int x, int y, Uint8 color)
{
/* Draws a pixel on the screen at (x, y) with color 'color' */
Uint8 *p;
p = (Uint8 *) screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
*p = color;
}
It also compiles without warnings. The (Uint8 *) cast (copied from the original) is unnecessary. With the class definition given, it is superfluous; if you are needing to use a cast because the type of the pixels member of SDL_Surface actually isn't Uint8, are you sure it is a good idea? And can't you use reinterpret_cast<Uint8>(screen->pixels) instead to make it clearer?
Can you reduce your problem to code analogous to this that still shows the actual error?

C++ Header File Needs a Reference to a Function of Another Class

I have incorporated polymorphism with a single subclass for now. Two of these functions, as seen in the following code, Draw() and SetValue(int,int,int) are causing linker errors.
#include "Header.h"
class Object{
int tag;
public:
void SetValues(int,int,int);
void Draw();
int getTag(){
return tag;
}
};
class Square: public Object{
int red;
int green;
int blue;
void Draw();
void SetValues(int red2,int green2, int blue2){
red=red2;
green=green2;
blue=blue2;
}
};
void Square::Draw(){
// Draws a square with a gradient color at coordinates 0, 10
glBegin(GL_QUADS);
{
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
}
glEnd();
}
The errors
Error 1 error LNK2019: unresolved external symbol "public: void __cdecl Object::SetValues(int,int,int)" (?SetValues#Object##QEAAXHHH#Z) referenced in function "public: void __cdecl State::DrawAll(void)" (?DrawAll#State##QEAAXXZ) C:\Users\Asher\documents\visual studio 2012\Projects\Procedural Terrain\Procedural Terrain\State.obj Procedural Terrain
Error 2 error LNK2019: unresolved external symbol "public: void __cdecl Object::Draw(void)" (?Draw#Object##QEAAXXZ) referenced in function "public: void __cdecl State::DrawAll(void)" (?DrawAll#State##QEAAXXZ) C:\Users\Asher\documents\visual studio 2012\Projects\Procedural Terrain\Procedural Terrain\State.obj Procedural Terrain
In a larger class, which does no inherit Object's functions, uses DrawAll() with a Draw() call in it.
The cpp file and the two respective header files are as follows.
#include "Header.h"
#include "Object.h"
float rotate_z=0;
class State{
private:
std::vector<Object> storage;
public:
State();
State Interpolate(State, State, double);
void Integrate(State,double, const double);
void DrawAll();
void AddObject(Object);
void RemoveObject(int);
};
State::State(){
}
State State::Interpolate(State current,State previous,const double alpha){
//current*alpha + previous * ( 1.0 - alpha );
return current;
}
void State::Integrate(State current, double t, const double dt){
}
void State::AddObject(Object object){
storage.push_back(object);
}
void State::RemoveObject(int tag){
//for(int i=0;i<storage.size;i++){
// if(storage.at(i).getTag==tag){
//storage.erase(storage.begin()+i);
// }
//}
}
void State::DrawAll(void)
{
// reset view matrix
glLoadIdentity();
// move view back a bit
glTranslatef(0, 0, -30);
// apply the current rotation
glRotatef(rotate_z, 0, 0, 1);
rotate_z += 5;
// by repeatedly rotating the view matrix during drawing, the
// squares end up in a circle
int i = 0, squares = 15;
float red = 0, blue = 1;
for (; i < squares; ++i){
Square square;
Object * squareP=&square;
glRotatef(360.0/squares, 0, 0, 1);
// colors change for each square
red += 1.0/12;
blue -= 1.0/12;
squareP->SetValues(red,0.6,blue);
squareP->Draw();
}
}
The Object header -
#ifndef Object_H
#define Object_H
class Object{
int tag;
public:
void SetValues(int,int,int);
void Draw();
int getTag();
};
class Square: public Object{
int red;
int green;
int blue;
void Draw();
void SetValues(int red2,int green2, int blue2);
};
#endif
Lastly the State header -
#ifndef State_H
#define State_H
#include "Object.h"
#include <vector>
class State{
private:
std::vector<Object> storage;
public:
State();
State Interpolate(State, State, double);
void Integrate(State,double, const double);
void DrawAll();
void AddObject(Object);
void RemoveObject(int);
};
#endif
This is the first C++ project I have worked on and have not fully transferred from a Java background. What could the problem be?
Your Object class has no implementation of SetValues function. You may want a pure virtual function. Same for Draw.
class Object {
virtual void SetValues(int,int,int) = 0;
}
Also note that in C++ functions are not virtual by default. You have to use the virtual keyword explicitly in the base class.
Also class Object seems to be defined at multiple places. Why? Defining it in Object.h would be sufficient.
Also please indent your code because it is very hard to read.
Also std::vector<Object> will not do what you want! Unline Java, where everything is a reference, in C++ things are stored by value in an std::vector and therefore your code is subject to the slicing problem. You want to use at lease a pointer there (std::vector<Object*>) but a smart pointer would be even better (std::vector<std::shared_ptr<Object>>)
Nothing is marked as virtual, and I can't see any implementation for Object::Draw() or Object::SetValues().
In C++ to allow a subclass to override a function in the base class, it needs to be marked as virtual (in Java everything is always "virtual").
You can have "abstract" methods (like Java) by saying
class Object {
public:
virtual void SetValues(int,int,int) = 0;

Overloading difficulty with an extended sprite class. How is this wrong?

So I've been working on a puzzle game using a sprite system I used fine previously and in my past projects have been fine when extending the class, however my code keeps throwing an error of
error C2511:
'Door:: Door(float,float,float,float,float,float,int,CGame *)' :
overloaded member function not found in 'Door'
and I have no idea why as i've checked all the classes in my previous project and how they interface with the rest of the program and it's IDENTICAL but this new class is still erroring out. and the code in my main to create the object throws "no overloaded function in Door takes 8 arguments" out.
Door Class:
Door.h
#pragma once
#include "sprite.h"
class CGame;
class Door :
public CSprite
{
public:
Door(void);
Door(float, float, float, float,float, float, float, int, CGame * p_Game);
void Update(float dt);
~Door(void);
private:
};
Door.CPP
#include "stdafx.h"
#include "Door.h"
#include "Game.h"
Door::Door(void)
{
}
//So this is where i try to make door class extend sprite. but it keeps saying "overloaded member function not found in Door"
//and the other error is "doesnt take 8 args" and to top it off. It says unexpected end of file.
//Uncomment this block and the code in the door bit of the map gen to see what it is doing wrong
Door::Door(float _x, float _y, float _w, float _h, float _vX, float _vY, int _texID, CGame * p_Game) : CSprite(_x, _y, _w, _h, _vX, _vY, _texID, p_Game)
{
m_iType = 4 //sets the type of sprite that this object is.
}
void Door::Update(float dt)
{
}
Door::~Door(void)
{
}
and this is the sprite class i am extending (just the relevant parts)
Sprite.h
#pragma once
class CGame;
class CSprite
{
public:
float m_fX; //the position of the centre of the sprite
float m_fY;
float m_fW; //width of the sprite in arbitrary units
float m_fH; //height of the sprite in arbitrary units
float m_fvX;
float m_fvY;
int m_iTextureID; //which of the preloaded textures to use
float m_fR; //red component between 0 and 1
float m_fG; //green component between 0 and 1
float m_fB; //blue component between 0 and 1
float m_fA; //alpha value 0-1
int m_iType;
CGame * m_pGame;
public:
CSprite();
CSprite(float x, float y, float w, float h,float vX,float vY, int textureID ,CGame * p_Game);
bool bIsCollidingWith( CSprite * othersprite_);
bool markedForDelete;
//This new constructor is added to the Csprite.h header file.
float getX() { return m_fX; }
float getY() { return m_fY; }
virtual bool TagForDeletion();
virtual int GetSpriteType();
virtual ~CSprite();
virtual void Render();
virtual void Update(float dt);
};
Sprite.cpp
#include "StdAfx.h"
#include <gl.h>
#include <glut.h>
#include <glaux.h>
#include "main.h"
#include "sprite.h"
#include "Game.h"
CSprite::CSprite( )
{
m_fX=0.0f;
m_fY=0.0f;
m_fW=1.0f;
m_fH=1.0f;
m_fvX=0.0f;
m_fvY=0.0f;
markedForDelete=false;
m_fR=m_fG=m_fB=m_fA=1.0;
m_iTextureID=0;
}
CSprite::CSprite(float x_, float y_, float w_, float h_,float vX_,float vY_, int textureID_, CGame * p_Game)
{
m_iType = 1;
m_fX=x_;
m_fY=y_;
m_fW=w_;
m_fH=h_;
m_fvX=vX_;
m_fvY=vY_;
m_fR=m_fG=m_fB=m_fA=1.0;
m_iTextureID=textureID_;
m_pGame = p_Game;
markedForDelete=false;
}
CSprite::~CSprite(void)
{
}
Implementation in the game class uses the parameters extended from Sprite to create the object
p_Door[m_iSpritesLoaded++]=new Door(uiRow,4.58 -uiCol,1,1,0,0,4,this);
You miscounted your floats.
Declaration
Door(float, float, float, float,float, float, float, int, CGame * p_Game);
// 1 2 3 4 5 6 7
Definition
Door::Door(float _x, float _y, float _w, float _h, float _vX, float _vY, int _texID, CGame * p_Game)
// 1 2 3 4 5 6
: CSprite(_x, _y, _w, _h, _vX, _vY, _texID, p_Game)
Usage
p_Door[m_iSpritesLoaded++]=new Door(uiRow,4.58 -uiCol,1,1,0,0,4,this);
// 1 2 3 4 5 6
(Did you really need Stack Overflow for this?!)
Looks like your Door constructor has one extra float parameter. The declaration has 7 floats whereas the definition in Door.cpp has 6.
In Door.h the constructor has 9 arguments
Door(float, float, float, float,float, float, float, int, CGame * p_Game);
while in the Door.cpp the definition of the constructor has only 8 elements, that is one float is missing.
Solution:
add one argument to the definition of the constructor
CSprite::CSprite(float x_, float y_, float w_, float h_,float vX_,float vY_, int textureID_, CGame * p_Game)