Declaring a template class with two template params a friend in anon-template class

A

A L

I have an abstract class:

class Attribute { /* ...*/ };

Now I have another class:

template <typename T, typename U>
class Mgr
{
static U *create(const std::string k, std::string v)
{
static T *p = 0;
if (!p)
{
p = new T();
}
T &r = *p;
U *a = const_cast<U*>(r.get(k));
return a;
}
};

Both of these classes are declared/defined in different header files.

The problem is that the constructors of Attribute class are private so
I have to declare the Mgr class a friend of Attribute. That's what I
have a problem doing - I am having a difficult time with the template
syntax when it comes to declaring a template class (with two template
parameters) a friend in a non-template class - I am getting lots of
compilation errors on the friend template declaration. Can any kind
sole tell me how I am supposed to do it? Declare a template class with
two template parameters a friend in a non-template class???

-Thanks/AL
 
A

Alf P. Steinbach /Usenet

* A L, on 25.08.2010 08:17:
I have an abstract class:

class Attribute { /* ...*/ };

Now I have another class:

template<typename T, typename U>
class Mgr
{
static U *create(const std::string k, std::string v)
{
static T *p = 0;
if (!p)
{
p = new T();
}

Above is unnecessary because C++ does it for you:

static T *p = new T();

T&r = *p;
U *a = const_cast<U*>(r.get(k));

This const_cast seems pretty dangerous.

return a;
}
};

Both of these classes are declared/defined in different header files.

The problem is that the constructors of Attribute class are private so
I have to declare the Mgr class a friend of Attribute. That's what I
have a problem doing - I am having a difficult time with the template
syntax when it comes to declaring a template class (with two template
parameters) a friend in a non-template class - I am getting lots of
compilation errors on the friend template declaration. Can any kind
sole tell me how I am supposed to do it? Declare a template class with
two template parameters a friend in a non-template class???

Design Attribute as a singleton.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top