C++ :: Game Engine - Instancing A Class Via Constructor
Apr 23, 2013
I'm making a little "game engine" for a Rogue-Like game series I'll develop beside a friend. This "game engine" was programmed originally in ms-dos batch 6 years ago by me, and was evolving since. It have a VB6 version, a VB .net version, and a Python version... lately a C++ version following the same method of the first stable release of ms-dos batch (isn't weird?). As you can see, is a mere hobby.
Well, I have 1 headers for my C++ version of the engine, in that *.h file I have 2 classes (for now). The first class, and maybe the most important one, contains the code of the map handling (drawing, verification, creation, modification etc.) and the second one is the Object class, which code the "actors" or "npc" basic functions as movement, coloring, instancing etc...
The second class depends of the first class to function, because the first class is the responsible of displaying all inside the map.
The problem is that the class Object needs an instance of the class Map where the Object will be, but... that's the problem, the code seems right, but when is about to run it crash reporting a "No matching function for call to 'Map::Map()'" in the line 91 of AGE.h (that's the Object class constructor)... and its all.
So, this is the code of the main header that contains these classes:
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#define Up 0
#define Down 1
#define Left 2
[Code] ....
A simple code that uses "AGE.h" for test purposes...
View 7 Replies
ADVERTISEMENT
Mar 18, 2013
I'm making a small game engine and have a project in Code::Blocks for it, and a project to test it out. The thing is that my test program won't find a constructor from the engine. Here's my code:
Game Engine, Screen.hpp
#ifndef SCREEN_HPP_INCLUDED
#define SCREEN_HPP_INCLUDED
#include "SDL.h"
namespace myeng {
class Screen final //This class doesn't need to be derived from
[Code] ....
I have my engine project correctly linking to the SDL dlls and the test project linking to the engine dll and the SDL dlls. The errors are:
objDebugmain.o||In function `SDL_main':|
C:UsersMainDocumentsProgramsGame_Engine_Testmain.cpp|12|undefined reference to `myeng::Screen::Screen(int, int)'|
C:UsersMainDocumentsProgramsGame_Engine_Testmain.cpp|16|undefined reference to `myeng::Screen::~Screen()'|
||=== Build finished: 2 errors, 0 warnings ===|
View 7 Replies
View Related
Jul 19, 2013
What i'm trying to do is create a 3d game engine with opengl and i want to be multi platform. I'm trying to use code-blocks for this reason but i'm having trouble setting up opengl for code-blocks
View 1 Replies
View Related
Aug 6, 2013
I want to write a game engine with MinGW and Code::blocks ide
[URL] ....
This is my project's source code
[URL] .....
This is the build log.
I can't code it here, because it's two large to add the characters!
View 10 Replies
View Related
Jan 1, 2013
Is this example correct? This example from a book
Constructor of the Base Class
Person::Person(char* n="", char* nat="U.S.A", int s=1)
{
name = n;
nationality = nat;
sex = s;
}
Constructor of the Derived Class (inherited from the base class)
Student(char* n, int s=0, char* i=""):
Person(n, s)
Why the initialized list of the base class constructor doesn't match the initialized list of the derived class constructor? I know this book is a little bit old, I'm not sure if this wrong in VC++ 2010?
View 5 Replies
View Related
Mar 19, 2015
to initialize this object? Why C++ FAQ says no? Here is my code,
Code:
class A
{
public:
A(int x, char c);
A(int x);
[code] ....
I don't have any trouble to call the constructor A(int x, char c) from another constructor A(int x).
View 10 Replies
View Related
Jan 6, 2015
Let's say I have a Car object , and it contains inner Engine object.
Code:
struct Car{
Engine mEngine;
};
In order to initialize the engine object NOT by the default constructor (if it has any) , we use initialization semantics:
Code:
Car::Car:
mEngin(arg1,arg2,...)
{
other stuff here
}
Now it gets tricky: Let's say a Car objects has 10 inner objects, each object has about 5 variables in it . Car is a base class for , e.g. , Toyota class. you don't want the Car class to have a constructor with 50 arguments. Can the inner objects of Car be initialized from the base class , e.g. Toyota?
Code:
class Toyota:
Car(...),
mEngine(...),
mGear(..)
{
...
};
The other options are:
1) like said , create a Car constructor which gets 50 arguments, then initialize Car as whole from Toyota - the code becomes less readable and less intuitive
2) Car constructor which get built-objects as arguments and initialize the inner objects with copy constructor . the code gets more readable but then you create many excess objects .
View 5 Replies
View Related
May 15, 2013
I understand it is done like this
// Calling the base class constructor
explicit CCandyBox(double lv, double wv, double hv, const char* str="Candy"): CBox(lv, wv, hv)
{
...
}
But how does the compiler know that you are initializing the base "part" of the object?
Or is this the entire reason initialization lists exist, to separate this confusion?
View 4 Replies
View Related
Feb 28, 2012
I am trying to use constructor within constructor in the same class. Is that possible. I have tried something and it shows me a error message:
error: type "mainClass" is not a direct base of "glavna"
This is the program I tried:
Code:
class mainClass {
private:
int x,y;
Code] ......
View 6 Replies
View Related
Sep 20, 2013
Suppose I have two classes A and B so how to access object of class A in constructor of B's class as a parameter.
View 6 Replies
View Related
May 29, 2013
I really confused with constructor (default constructor and constructor with parameters)
I coded this problem
and I worked almost, but I stock in constructor
Code:
class Tier {
public:
enum TIER_MAKE
[Code] ....
This is tier class and I have to finish constructor in class car (for simple, I skip detail code) -red things are the parts from class Tier
Code: Car()
: make(NULL), passengers(0), fuelcap(0.0), efficiency(0.0), tier(Tier::nexen)
{ }
[Code] ....
And someone said default constructor part has to be this
Code:
car( Tier::TIER_MAKE p_tiermaker = Tier::nexen )
//after i skip
but default constructor should be no parameter...? isn't it?
View 1 Replies
View Related
Mar 22, 2014
# include <iostream>
# include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
class Course
// Creating the class Course
[Code] ....
Errors: Warning1warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
[Code] .....
I have to create an Array of type Course and then fill its member dats using various member functions. Those errors are caused by some Constructor defect, which I dont really know what it is.
View 2 Replies
View Related
Jan 13, 2015
I recently designed a struct like this
// MyMap.h
typedef std::map<std::string, std::function<void ()>> MyMap;
extern MyMap g_mymap;
// MyMap.cpp
My Map g_mymap;
[Code] ....
It looks useful to implement strategy pattern because it makes a fully separate code block. So I can add a function to the map simply by compiling a source file. It's very simple. I don't need to edit another file.
But when I use it for my existing project, It makes some linking and runtime errors.(vs 2012). I can't recognize exactly why because it is a huge project. Anyway, I have a question that - Is this a safe use of class constructor?
I know that there is no fixed order of running, but in this case I think it doesn't matter. because they are independent. But it is not a common pattern, so I can't decide to use it.
View 3 Replies
View Related
Nov 15, 2012
This is my class there is a problem with my copy constructor .. is that correct ??
struct Node {
Type info;
Node<Type> *next;
};
template <class Type>
class Queue
[Code] ....
View 1 Replies
View Related
Jul 14, 2014
Firstly I don't really know if this is possible.
This is my Class Diagram: [URL]...
github: [URL]...
I want to redefine the price object of the Book Class. However price is defined at Products Class.
I want the price value change according to the marker value, which is a Book attribute.
If the marker is blue, price gets a value of 10 (e.g.), if it has another value, price is equal to 20.
View 10 Replies
View Related
Jun 27, 2013
Basically, I need to set a variable outside of the constructor and make it accessible to the entire class.
It would need to work something like this:
#include <iostream>
#include <string>
template <typename MT> class CallbackFunction
{
[Code].....
View 5 Replies
View Related
Feb 14, 2013
I am making a snake game just to give some context.
//LevelObject.hpp
class LevelObject {
public:
virtual void Update() = 0;
virtual void Draw(Canvas& canvas) = 0;
protected:
Vector3 location_;
[Code] ....
The problem I have is with the Size constructor and the abstract class LevelObject which size is a member of.
The compiler error I get is:
C:Program Files (x86)ProgrammingProjectsUniversityprg_interactivesnakey_takeysrc..inc..incPlayer.hpp|17|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]|
C:Program Files (x86)ProgrammingProjectsUniversityprg_interactivesnakey_takeysrc..inc..inc..incPlayer.hpp|17|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]|
[Code] .....
However I do invoke the copy constructor when I pass a variable of type size to the constructor in this line:
size_ = Size(s);
But the problem is that its complaining that the abstract class LevelObject doesn't invoke the constructor, which it shouldn't.
View 2 Replies
View Related
May 17, 2013
When the below is done, does it call the constroctor only, and if yes, constructors do not have return types so how does it work? is there anything behind the scene?
wxAddHandler(new wxPNG_HANDLER);
and
sf::RenderWindow(sf::VideoMode(...),...);
View 6 Replies
View Related
Mar 12, 2012
Can I determine if a templated class has a particular constructor, in my case using a string within function to which T is used?
Code:
template<class T>
void MakeObject(std::vector<T>& dataVector)
{
std::string str "con string,Joe,24";
// catch if T has string constructor
T someObject(str); // T someObject should have constructor from string
dataVector.push_back(someObject);
}
View 1 Replies
View Related
May 5, 2013
I am unable to understand how a move constructor works in this example of code. If someone could break down the process of what is taking place and explain to me on why to use a move constructor.
Code:
class MyString {
MyString(MyString&& MoveSource) {
if( MoveSource.Buffer != NULL ) {
Buffer = MoveSource.Buffer; // take ownership i.e. 'move'
MoveSource.Buffer = NULL; // set the move source to NULL i.e. free it
}
}
};
Example from "SamsTeachYourself: C++ in One Hour a Day"
View 1 Replies
View Related
Mar 7, 2015
I keep getting following errors:
multiple definition of `SDL2Graphics::SDL2Start()'
undefined reference to `SDL2Graphics::SDL2Graphics()'
My set up is as follows:
Main.c++:
#include <iostream>
#include "GL/gl.h"
#include "GL/glu.h"
#include "SDL2graphics.c++"
/* Global variables */
int main(int argc, char* argv[]) {
[Code] ....
View 1 Replies
View Related
May 1, 2013
I am trying to pass an object to an inherited clas by a constructor. I am having Cboard my board and i need to pass it to the object Cpawn.
Here under is my code:
main
Code:
#include<iostream>#include "Cboard.h"
#include "Cpawn.h"
#include "Cpiece.h"
void main(){
char location[50];
[Code] ....
View 3 Replies
View Related
Jun 18, 2013
I have three classes 1 base and two inherited.. problem is when I try to initialize the it says undefined reference to vtable constructor.
Code:
#ifndef QUOTE_H_INCLUDED
#define QUOTE_H_INCLUDED
#include <string>
using namespace std;
[Code] ....
View 2 Replies
View Related
Mar 25, 2013
I'm trying to make a class constructor within a namespace and I keep getting errors like: "'<variable>' is a nonstatic data member of class '<class>'" for when I try to setup parameters, and "Incomplete type is not allow" whenever I try to write out my function definition. Here's what I'm doing:
namespace test {
class blah;
} class blah {
typedef int var[5];
[Code] .....
Also I'm unsure why there is a parameter of 'const blah &' when I mouse over blah(); (using Visual Studio 2010) within the class definition. It tells me 'blah::blah(const blah &)' and I am unsure where the parameter comes from. How can I resolve these issues?
View 4 Replies
View Related
Nov 14, 2013
I'm writing a class that has two constructors. However, I can't get them to work quite right. One constructor has a parameter of an int (with a default value of 0) and the other has a parameter of a C-style string.
First of all, are these function prototypes correct for the constructors?
MyInt(int n = 0);// first constructor, int param, default value 0
MyInt(const char * c);// second constructor, c-style string param
Both constructors work fine in some cases but don't work in all cases. Here are some potential calls to these functions that are supposed to work:
// These two work fine
MyInt x(12345),
y("9876543210123456789"),
// The array assignment doesn't work when the value is negative
// I'm not allowing negative numbers, but I want to create the object and assign the array to 0
r1(-1000),
[Code] .....
Here's the private data from the class (from the header file):
private:
int currentSize,
maxSize;
char* digits;// Pointer to an array of digits
// Increase the size of digits array by 5
void Grow ();
View 2 Replies
View Related
Jul 27, 2014
I have one base class and one derived class.
class Base
{
protected:
int a, b;
[Code]....
The two definition of the derived class constructor
(Derived(int aa, int bb, int cc) { Base(aa, bb); c = cc; }
and
Derived(int aa, int bb, int cc) : Base(aa, bb), c(cc) {}
looks identical but first one does not work.
So, I wounder what the difference between them?
View 1 Replies
View Related