Question about Loki::Singleton



 DEVELOP > c-Plus-Plus > Question about Loki::Singleton

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Krivenok Dmitry"
Date: 24 Mar 2006 06:07:20 AM
Object: Question about Loki::Singleton
Hello All!
This is example of code:
//////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef A_H_
#define A_H_
#include <Loki/Singleton.h>
#include <Loki/SmartPtr.h>
#include <iostream>
class A
{
public:
A() { std::cout << "A constructor" << std::endl;}
~A() { std::cout << "A destructor" << std::endl;}
};
typedef Loki::SingletonHolder<
Loki::SmartPtr<A>,
Loki::CreateUsingNew,
Loki::NoDestroy,
Loki::SingleThreaded

APtrSingleton_t;

#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
I can use APtrSingleton_t::Instance() in my program, but it's very
uneasily.
How to define (short) alternative name of APtrSingleton_t::Instance()?
Thanks!
.

User: "Ben Pope"

Title: Re: Question about Loki::Singleton 24 Mar 2006 06:53:05 AM
Krivenok Dmitry wrote:

Hello All!

This is example of code:
//////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef A_H_
#define A_H_

#include <Loki/Singleton.h>
#include <Loki/SmartPtr.h>
#include <iostream>

class A
{
public:
A() { std::cout << "A constructor" << std::endl;}
~A() { std::cout << "A destructor" << std::endl;}
};

typedef Loki::SingletonHolder<
Loki::SmartPtr<A>,
Loki::CreateUsingNew,
Loki::NoDestroy,
Loki::SingleThreaded

APtrSingleton_t;

#endif
//////////////////////////////////////////////////////////////////////////////////////////////////

I can use APtrSingleton_t::Instance() in my program, but it's very
uneasily.
How to define (short) alternative name of APtrSingleton_t::Instance()?

Thanks!

A* x() {
return APtrSingleton_t::Instance();
}
Then whenever you want the instance, just do:
A* a = x();
Not very useful if you ask me, though.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
.

User: "mlimber"

Title: Re: Question about Loki::Singleton 24 Mar 2006 07:01:11 AM
Krivenok Dmitry wrote:

Hello All!

This is example of code:
//////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef A_H_
#define A_H_

#include <Loki/Singleton.h>
#include <Loki/SmartPtr.h>
#include <iostream>

class A
{
public:
A() { std::cout << "A constructor" << std::endl;}
~A() { std::cout << "A destructor" << std::endl;}
};

typedef Loki::SingletonHolder<
Loki::SmartPtr<A>,
Loki::CreateUsingNew,
Loki::NoDestroy,
Loki::SingleThreaded

APtrSingleton_t;

#endif
//////////////////////////////////////////////////////////////////////////////////////////////////

I can use APtrSingleton_t::Instance() in my program, but it's very
uneasily.
How to define (short) alternative name of APtrSingleton_t::Instance()?

Thanks!

You could create a macro (yuck!), an inline function, or a local
reference (my preference):
Loki::SmartPtr<A>& ptr = APtrSingleton_t::Instance();
Cheers! --M
.

User: "Krivenok Dmitry"

Title: Re: Question about Loki::Singleton 24 Mar 2006 10:00:10 AM
Of course s/Loki::SmartPtr<A>/A*/g :))
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER