Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-07-2007, 04:40 PM   #1
LQ Guru
Registered: Apr 2003
Location: nottingham england
Distribution: Gentoo
Posts: 2,672

Rep: Reputation: 47
help overloading 'new' operator c++

Hello Guys,

Im working on a multi platform ( windowsXP / linux / embedded linux / embedded windowsXP) 2d game engine.

until very recently, my new engine was source code compatable with games written for a game engine that works for an embedded 68k machine ( low powered arcade video game )

I used to achive this muti platform compatability with an ugly mess if #ifdef PLATFORM_X's

However In the latest version, ive replaced a million #ifdef LINUX_CONSOLE / LINUX_GEODE LINUX_X11 / DIRECTX / OPENGL / WIN32 with a nice simple plugin architechture.. all OS / API dependant code lives inside its own shared object to be linked at runtim depending on the envoronment.

ANWAYS... It would be Great if i could keep this plugin engin code compatable with the Game source code.

The current games would create a new Blittable Image with code like so...

CGraphic *Graphic = new CGraphic(SomeData)

But with the Plugin architecture, this is not possable, as the game knows nothing of the Graphics format ( as it is api dependant ), it only knows its abstract base class.

In my new plugin system, the games code for Creating A Graphic Has to be...

IGraphic *Graphic = GetGraphicFromLoadedVideoPlugin(SomeData);

I Would Prefere to not have to change all the game code....

Is it possable to overload the new operator of an Abstract class to return
GetGraphicFromLoadedPlugin(SomeData); ????

Old 03-07-2007, 04:58 PM   #2
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Trying to override new() to do that won't help because new only cares about allocating memory and knows nothing about types. Really, best option is a human-guided find-and-replace using a good editor.

Or figure out something different for the multi-platform stuff. Doing stuff in runtime that could be "easily" done compiletime seems bad. One somewhat standard way is to have a "platform.hpp" with all the #ifdefs, like
#include "linux/platform.hpp"
#include "linux-geode/platform.hpp"
#elsif LINUX_X11
#include "linux-x11/platform.hpp"
#elsif DIRECTX
#include "directx/platform.hpp"
#elsif OPENGL
#include "opengl/platform.hpp"
#elsif WIN32
#include "win32/platform.hpp"

Last edited by tuxdev; 03-07-2007 at 05:03 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ [] operator overloading exodist Programming 12 04-17-2004 03:06 PM
C# with dotGNU, operator overloading exodist Programming 2 03-15-2004 05:52 PM
Builtin operator overloading. exodist Programming 15 03-11-2004 10:41 PM
c++ overloading input operator true_atlantis Programming 4 02-25-2004 07:24 PM
Operator Overloading - Java? Tesl Programming 4 02-13-2004 12:54 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration