Mylo's Profile
Reputation: 165
Stalwart
- Group:
- Active Members
- Active Posts:
- 588 (1 per day)
- Joined:
- 11-October 11
- Profile Views:
- 4,691
- Last Active:
Today, 12:24 AM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Who Cares
- Favorite Browser:
- Who Cares
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Caching shared resources
Posted 10 May 2013
The images would be loaded from a file in my circumstance. Additionally, the class has an enum variable determining it's identity (a shopkeeper, merchant etc) At the moment, I would be going with the map idea. It's a small project, so anything is easy to change. I just like to know about alternative methods of doing such things even if I may not use them.
Edit: Oops, didn't notice your post until now, stackoverflow, sorry. I'll definitely do that. I haven't looked at smart pointers either, (preferring to implement things myself gets in the way) so now would be a good time too, even if I use them or not, thanks.
Now if I wanted to have the wrapper class manage multiple types of data (As opposed to just Images), would it be in preference to hold mutliple maps each committed to one kind of resource, or create a class for each type of resource I need and implement some interface like IResource? I would think the interface personally as I could then completely ignore the implementation of the wrapper class. -
In Topic: Mulitple different errors in STL for simple code
Posted 7 May 2013
Ok
/>/>/>
Just realised I have forgotten to set the pointers to null the board elements. That fixed the problem.
Quote
I think you need to review dynamic memory. The memory you're allocating is not necessarily one continuous block.
See this link for a better explanation. 3d array although there talking about a 3d array the answers are the same for a 2d array.
Thanks for the link, I'll be sure to revise it. Have looked at like 50 other pages on the topic, and have not been able to find a clear answer on all of creating/accessing arrays dynamically. -
In Topic: Mulitple different errors in STL for simple code
Posted 7 May 2013
I don't understand what that stack trace is saying sorry.
But by running through the debugger (VS), I get to i = 0, j = 8, with a getAt() return of 0xfdfdfdfd.
However, i * mCols + j = 0 * 16 + 8 = 8, which should give me the 8th element as I believe the way I have created the array causes it to be sequential in memory? Of course if that is incorrect, the problem is clear. -
In Topic: Mulitple different errors in STL for simple code
Posted 7 May 2013
Sorry about that Jim, that part was from when I did change to vectors, I have removed it above now, no other code has changed. They were commented out when receiving the errors.
On that topic anyhow, if inside the setAt() function, I am assigning the pointer to an array index, should I not be able to access them via those array indexes later? (ie. memory is not lost?) -
In Topic: Mulitple different errors in STL for simple code
Posted 7 May 2013
Sure, although i'm not directly using main as such, so i'll post the rest of the files.
City.h
#ifndef CITY_H #define CITY_H class City { protected: bool alive; bool shown; public: static const char ALIVE_CHAR = 'C'; static const char EMPTY_CHAR = ' '; static const char INTEL_CHAR = '/'; static const char NUKED_CHAR = '*'; City(void); ~City(void); void render(); }; #endif
city.cpp
#include <iostream> #include "City.h" using std::cout; City::City() { alive = true; shown = true; } void City::render() { if (alive) { if (shown) cout << ALIVE_CHAR; else cout << EMPTY_CHAR; } else cout << NUKED_CHAR; } City::~City(void){}
Main.cpp
#include "ABApplication.h" int main(int argc, char ** argv) { ABApplication * app = createApplication(); if (app->processArgs(argc, argv)) app->init(); while (app->isRunning()) app->update(); app->cleanup(); delete app; system("pause"); }
ABApplication.h
#ifndef ABAPPLICATION_H #define ABAPPLICATION_H class ABApplication { private: bool mIsRunning; int mArgc; vector<string> mArgv; protected: virtual void _init() = 0; virtual void _update() = 0; virtual void _stop() = 0; virtual void _cleanup() = 0; virtual bool _processArgs(const vector<string> & argv); public: ABApplication(); virtual ~ABApplication() = 0; void init(); void update(); void stop(); void cleanup(); bool processArgs(int argc, char ** argv); bool isRunning(); }; ABApplication * createApplication(); #endif
ABapplication.cpp
#include "ABApplication.h" ABApplication::ABApplication(void) { mArgc = 0; mIsRunning = false; } void ABApplication::init() { _init(); mIsRunning = true; } void ABApplication::update(){_update();} void ABApplication::stop() { _stop(); mIsRunning = false; } void ABApplication::cleanup(){_cleanup();} bool ABApplication::processArgs(int argc, char ** argv) { string toAdd; for (int i = 1; i < argc; ++i) { toAdd = argv[i]; mArgv.push_back(toAdd); } return _processArgs(mArgv); } bool ABApplication::_processArgs(const vector<string> & argv){return true;} bool ABApplication::isRunning(){return mIsRunning;} ABApplication::~ABApplication(void){}
ThermoWar.h
#ifndef THERMOWAR_H #define THERMOWAR_H #include "ABApplication.h" #include "Board.h" class ThermoWar : public ABApplication { static const int MAX_CITY = 15; // Per Side static const int MAX_COLS = 5; // static const int MAX_ROWS = 8; // ... static const int MIN_CITY = 12; // Per Side static const int MIN_COLS = 3; // ... static const int MIN_ROWS = 4; // ... protected: Board * mpGameBoard; void _init(); void _update(); void _stop(); void _cleanup(); bool _processArgs(const vector<string> & argv); public: ThermoWar(); ~ThermoWar(); }; #endif
Thermowar.cpp ( Class creating and using Board )
#include "City.h" #include "ThermoWar.h" ABApplication * createApplication() { return new ThermoWar(); } ThermoWar::ThermoWar() { mpGameBoard = NULL; } void ThermoWar::_init() { mpGameBoard = new Board(); } void ThermoWar::_update() { int rows = MIN_ROWS + rand() % (MAX_ROWS - MIN_ROWS); int cols = MAX_COLS + rand() % (MAX_COLS - MIN_COLS); mpGameBoard->init(8, 8); cout << endl; system("cls"); mpGameBoard->render(); cout << endl; cin.get(); } void ThermoWar::_stop(){} void ThermoWar::_cleanup(){} bool ThermoWar::_processArgs(const vector<string> & argv) { return true; } ThermoWar::~ThermoWar(){}
edit: compacted code for visibility.
My Information
- Member Title:
- D.I.C Addict
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Private
|
|


Find Topics
Find Posts
View Reputation Given
|