Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Templates: "implicit typename is deprecated" error and typedef'ing templates

Reply
Thread Tools

Templates: "implicit typename is deprecated" error and typedef'ing templates

 
 
Generic Usenet Account
Guest
Posts: n/a
 
      07-14-2005
This is a two-part question.

(1) I have implemented a "Datastructure Registry" template class. I am
getting no compiler warnings with older compilers, but newer compilers
are generating the following error messages:
warning: implicit typename is deprecated,
please see the documentation for details

Can someone kindly suggest how to get rid of these warnings? The
source code follows.

(2) I want to use the "Datastructure Registry" template class to
implement a "Registry of Singletons", as mentioned in the GoF Design
patterns book. For this I want to do something like this:

typedefine the "Datastructure Registry" template-class as the "Registry
of Singletons" template-class.

I have tried various things, but nothing seems to be working.

typedef DSRegistry SingletonRegistry;
typedef DSRegistry<class T> SingletonRegistry<class T>;
typedef template DSRegistry<class T> template SingletonRegistry<class
T>;
typedef DSRegistry<class T> template SingletonRegistry<class T>;

Thanks,
Gus

//////////////////////////////////////////////////
#ifndef _DSREGISTRY_H_
#define _DSREGISTRY_H_

#include <iostream>
#include <string>
#include <map>

using namespace std;

template <class T>
class DSRegistry
{
public:
virtual ~DSRegistry(){};

static DSRegistry& instance()
{
if(_instance == NULL)
_instance = new DSRegistry();
return *_instance;
};

bool addEntry(string name, T* ptr)
{
bool retVal = false;

if(_map.find(name) == _map.end())
{
pair<string, T*> newEntry;
newEntry.first = name;
newEntry.second = ptr;
retVal = _map.insert(newEntry).second;
}

if(retVal == false)
{
#ifdef DEBUG
cerr << "Datastructure with name " << name
<< " previously registered --- request rejected" << endl;
#endif
}
return retVal;
}

bool deleteEntry(string name)
{
bool retVal = false;

map<string, T*>::iterator itor = _map.find(name);

if(itor != _map.end())
{
_map.erase(itor);
retVal = true;
}

if(retVal == false)
{
#ifdef DEBUG
cerr << "Datastructure with name " << name
<< " not found --- request rejected" << endl;
#endif
}
return retVal;
}

T* operator()(const string name)
{
T* retVal = NULL;

map<string, T*>::iterator itor = _map.find(name);

if(itor != _map.end())
{
retVal = itor->second;
}

if(retVal == NULL)
{
#ifdef DEBUG
cerr << "Cannot map datastructure with name " << name
<< " --- request rejected" << endl;
#endif
}

return retVal;
}

protected:
DSRegistry(){};
static DSRegistry* _instance;
map<string, T*> _map;
};

#endif //_DSREGISTRY_H_


//////////////////////////////////////////////////
#include <iostream>
#include "DSRegistry.h"

using namespace std;

DSRegistry<int>* DSRegistry<int>::_instance = NULL;

main()
{
int i1 = 1, i2 = 2, i3 = 3;

DSRegistry<int>::instance().addEntry("First" ,&i1);
DSRegistry<int>::instance().addEntry("Second" , &i2);
DSRegistry<int>::instance().addEntry("Third" , &i3);

int *val = DSRegistry<int>::instance()("Third");

if(val)
cout << "Returned value " << *val << endl;

}

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-14-2005
Generic Usenet Account wrote:
> This is a two-part question.


Is it? Or is it simply a message with more than one question?

BTW, why did you cross-post to 'comp.sources.d'? I don't post there, I
don't know their rules, so, sorry, I am not cross-posting my reply.

> (1) I have implemented a "Datastructure Registry" template class. I am
> getting no compiler warnings with older compilers, but newer compilers
> are generating the following error messages:
> warning: implicit typename is deprecated,
> please see the documentation for details
>
> Can someone kindly suggest how to get rid of these warnings? [..]


Make sure to add 'typename' where your compiler suggests. Next time you
post about a compiler error message or a warning, indicate in the source
code _where_ the warning is emitted, _what_line_ it is related to.

> (2) I want to use the "Datastructure Registry" template class to
> implement a "Registry of Singletons", as mentioned in the GoF Design
> patterns book. For this I want to do something like this:
>
> typedefine the "Datastructure Registry" template-class as the "Registry
> of Singletons" template-class.
>
> I have tried various things, but nothing seems to be working.
>
> typedef DSRegistry SingletonRegistry;
> typedef DSRegistry<class T> SingletonRegistry<class T>;
> typedef template DSRegistry<class T> template SingletonRegistry<class
> T>;
> typedef DSRegistry<class T> template SingletonRegistry<class T>;


None of those are going to work. There is not "template typedefs" in C++
(yet). To create a typedef (a synonym to a type), you need _a_type_, not
a _template_. In any case, the registry needs to be a singleton itself,
probably. And if it will work with all other singletons in a certain way,
shouldn't they all be of the same [base] class then?

>
> Thanks,
> Gus
>
> [..]


V
 
Reply With Quote
 
 
 
 
Mr. Blackwell
Guest
Posts: n/a
 
      07-14-2005
Generic Usenet Account wrote:
> This is a two-part question.
>
> (1) I have implemented a "Datastructure Registry" template class. I am
> getting no compiler warnings with older compilers, but newer compilers
> are generating the following error messages:
> warning: implicit typename is deprecated,
> please see the documentation for details


add 'typename' in the line of the error message. For details see:
http://womble.decadentplace.org.uk/c...plate-faq.html

> Can someone kindly suggest how to get rid of these warnings? The
> source code follows.
>
> (2) I want to use the "Datastructure Registry" template class to
> implement a "Registry of Singletons", as mentioned in the GoF Design
> patterns book. For this I want to do something like this:
>
> typedefine the "Datastructure Registry" template-class as the "Registry
> of Singletons" template-class.
>
> I have tried various things, but nothing seems to be working.
>
> typedef DSRegistry SingletonRegistry;


What is DSRegistry? If It's a template you cannot typedef it like that.

> typedef DSRegistry<class T> SingletonRegistry<class T>;
> typedef template DSRegistry<class T> template SingletonRegistry<class
> T>;
> typedef DSRegistry<class T> template SingletonRegistry<class T>;


You seem to be confused about templates and typedefs. They work
differently!

 
Reply With Quote
 
Generic Usenet Account
Guest
Posts: n/a
 
      07-14-2005
Mr. Blackwell wrote:
> > typedef DSRegistry SingletonRegistry;

>
> What is DSRegistry? If It's a template you cannot typedef it like that.
>
> > typedef DSRegistry<class T> SingletonRegistry<class T>;
> > typedef template DSRegistry<class T> template SingletonRegistry<class
> > T>;
> > typedef DSRegistry<class T> template SingletonRegistry<class T>;

>
> You seem to be confused about templates and typedefs. They work
> differently!


Thanks for the clarification. After you mentioned about the
restriction on templates, I was able to get it working with
inheritance. Also, your suggestion of sticking in the "typename"
keyword worked.

///////////////////////////////////////////////
#ifndef _SINGLETONREGISTRY_H_
#define _SINGLETONREGISTRY_H_

#include "DSRegistry.h"

template <class T>
class SingletonRegistry : public DSRegistry<T>
{
};

#endif //_SINGLETONREGISTRY_H_


///////////////////////////////////////////////
#include <iostream>

#include "SingletonRegistry.h"

using namespace std;

DSRegistry<int>* DSRegistry<int>::_instance = NULL;

main()
{
int i1 = 1, i2 = 2, i3 = 3;

SingletonRegistry<int>::instance().addEntry("First " ,&i1);
SingletonRegistry<int>::instance().addEntry("Secon d" , &i2);
SingletonRegistry<int>::instance().addEntry("Third " , &i3);

int *val = SingletonRegistry<int>::instance()("Third");

if(val)
cout << "Returned value " << *val << endl;

}

-Gus

 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
templates, typename, and basic_streambuf method return type problems Christopher C++ 1 01-29-2008 07:11 AM
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Q: typename or not typename? Jakob Bieling C++ 2 03-14-2006 03:44 PM
Templates - Requiring typename to inherit from a particular class? Victor Bazarov C++ 6 10-21-2005 09:41 PM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM



Advertisments