Skip to main content
GameDev.net gamedev.net
🔒 Locked

static class?

Started by siddim Jun 13, 2002 at 10:22 AM 10 replies 500+ views
Original Post
siddim
siddim
hi, I am building a little system, and i want to have a fonction available everywhere in the code. This fonction will be in a class for sure and will need to be initialize(constructor). How can i make this work? this fonction will be to write down text in a full screen window, but i want it to be available everywhere(it''s for debuging), you can compare it to cout<<"text"; but in my case it''s a opengl fonction that wrote down text using a font texture. my function is ready and working but i don''t want to pass a pointer in each other class. How can i make that work? thanks Siddim.
Carrot
Carrot
Search for Meyer Singleton Pattern (or any other singleton pattern).
This site has an article you could check out too

http://www.gamedev.net/columns/gameengineering/singleton/page2.asp
siddim
siddim
ok thanks it solve my problem,

but now, is there some way to make the calling humm shorter? an alias or something?

ex:
CWriter::Instance()->setSpacing(0);
CWriter::Instance()->setFont(0);
CWriter::Instance()->Print(40,150,"Star Wars");

is a bit long, how did they make "cout"? can i make my own function like that adprint(x,y,"text"); without the :: -> thing?

thanks in advance.


[edited by - Siddim on June 13, 2002 2:28:55 PM]
jenova
jenova
namespace

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
uNiQue0815
uNiQue0815
that''s my keyword !!!!!!

namespace !!

what exactly is this (think i know, but not too sure), and how does it work ?? every attempt i started didn''t work at all... i''ve already read the msdn-stuff about it, but nothing helped.
could you plz explain & maybe post some sample-code ?

thx !
siddim
siddim
yea really good idea, i never quite get the using namespace std thing.
jenova
jenova
namespaces

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Evil Bill
Evil Bill
quote:
you can compare it to cout<<"text";

cout is a variable, not a function.
use an extern, like this:

  
// In TextOutput.h:

extern CDebugOut output;

// In TextOutput.cpp:

CDebugOut output;

// In Test.cpp:

#include "TextOutput.h"

void Moo()
{
output << "Baa";
output.SomeFunction();
}


Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
uNiQue0815
uNiQue0815
mmh... now that i know, what namespaces are, i''m a little bit disappointed
hoped, that something else was meant.

i wanted to :

class a
{
int x, y, z;
};

a obj;

main()
{
// "open ''namespace''"
x = 0; y = 0; z = 0;
// "close ''namespace''"
}

is THAT possible somehow ? (know, it''s off-topic, but since the debate touched this one a little bit...)

in pascal it worked using :

with (a) do
begin
x := 1; y := 1; z := 1;
end;

would really make things easy in c++ sometimes...
wild_pointer
wild_pointer
quote:
Original post by uNiQue0815
mmh... now that i know, what namespaces are, i'm a little bit disappointed
hoped, that something else was meant.

i wanted to :

class a
{
int x, y, z;
};

a obj;

main()
{
// "open 'namespace'"
x = 0; y = 0; z = 0;
// "close 'namespace'"
}

is THAT possible somehow ? (know, it's off-topic, but since the debate touched this one a little bit...)

in pascal it worked using :

with (a) do
begin
x := 1; y := 1; z := 1;
end;

would really make things easy in c++ sometimes...


just make a method to set them. ie a::set( int _x, int _y, int _z )



[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people

[edited by - wild_pointer on June 14, 2002 3:31:06 PM]
[size=2]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.