Click to See Complete Forum and Search --> : template


Kohinoor24
July 11th, 2002, 09:55 AM
I have a template class as follows:
I would like to make it a singelton class;
I did some thing as follows:,But It is showing me errors...

template<class _base>
class Writer:public _base

{
public:

}

static Writer<_base>* Instance();

};

template<class _base>
Writer<_base>* Writer<_base>::Instance()
{
static WriterThread<_base> theWriter();
return &theWriter;
}

Is it right?

Thanks in advance

zdf
July 11th, 2002, 10:08 AM
At first glance.


template<class _base>
class Writer : public _base
{
public:

} // syntax error
static Writer<_base>* Instance();
};

template<class _base>
Writer<_base>* Writer<_base>::Instance()
{
static WriterThread<_base> // WriterThread should be Writer
theWriter(); // function declaration, not constructor
return &theWriter;
}



Regards,

jfaust
July 11th, 2002, 10:12 AM
No compile errors with some changes:


template<class _base>
class Writer : public _base
{
public:
static Writer<_base>* Instance()
{
return theWriter;
}

private:
static Writer<_base>* theWriter;
};



Is this what you're looking for?

Jeff

jfaust
July 11th, 2002, 10:55 AM
Please don't post the same message on multiple forums. It's very annoying. I really hate to see something I answered already answered on another forum. I feel you've just wasted my time.

Jeff

Kohinoor24
July 11th, 2002, 11:03 AM
Iam Really sorry for that.Iam posting on multiple forums, to make sure that everyone sees it & to definetly get a reply back.

Once again Iam sorry for the inconvenience that it caused you.

jfaust
July 11th, 2002, 11:11 AM
At the very least, if you just can't resist, you should wait a bit before posting to the other forum.