LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 03-07-2007, 04:40 PM   #1
qwijibow
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); ????

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

Rep: Reputation: 110Reputation: 110
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
Code:
#ifdef LINUX_CONSOLE
#include "linux/platform.hpp"
#elsif LINUX_GEODE
#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"
#endif

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 08:17 AM.

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