473,226 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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

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;

}

Jul 23 '05 #1
3 2914
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
Jul 23 '05 #2
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!

Jul 23 '05 #3
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

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Alexander Malkis | last post by:
What's the semantical/syntactical difference between two keywords "class" and "typename" (apart from different spelling)? -- Best regards, Alex. PS. To email me, remove "loeschedies" from...
4
by: Sergei | last post by:
I ran into this problem. I needed to create an entry for access to a library of functions that are "extern C", and I just can't find the right syntax, if it exists at all ( I am using MSVC...
3
by: Blaless | last post by:
Hi, I have a problem compiling the next piece of code under Linux using g++ (both 3.4.3 and 4.0.1) template<typename T> class Table{ public: // typedef T (TBoxTest::*GetterType)(); typedef...
2
by: Al Grant | last post by:
VC++ .NET 7.1 gives me an internal error from this code. It worked fine in VC++ 6.0 and other compilers. Are there any patches/SP's available for the 7.1 compiler? template<typename T> struct a...
5
by: jimmy | last post by:
I am trying to simulate typedef template similar to the suggestion of Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm However when implementing typedef templates according...
4
by: Sacha | last post by:
I'm aware, that up to date, "typedef templates" are not defined within the C++ standard. The seemingly common workaround is this: template <class T> struct MyTypeDef { /* ultimately I need...
9
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
5
by: Damien | last post by:
Hi all, I'm using a pretty standard C++ Singleton class, as below: template <typename T> class Singleton { public: static T* Instance() {
0
by: mickey22 | last post by:
I have a function template decalred in the following way as T A :: Func(T rad, T level); /////A is my class And I am calling this function template in of my other member functions as ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.