473,695 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

This is a two-part question.

(1) I have implemented a "Datastruct ure 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 "Datastruct ure 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 "Datastruct ure Registry" template-class as the "Registry
of Singletons" template-class.

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

typedef DSRegistry SingletonRegist ry;
typedef DSRegistry<clas s T> SingletonRegist ry<class T>;
typedef template DSRegistry<clas s T> template SingletonRegist ry<class
T>;
typedef DSRegistry<clas s T> template SingletonRegist ry<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(na me) == _map.end())
{
pair<string, T*> newEntry;
newEntry.first = name;
newEntry.second = ptr;
retVal = _map.insert(new Entry).second;
}

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

bool deleteEntry(str ing 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 << "Datastruct ure with name " << name
<< " not found --- request rejected" << endl;
#endif
}
return retVal;
}

T* operator()(cons t 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().ad dEntry("First" ,&i1);
DSRegistry<int> ::instance().ad dEntry("Second" , &i2);
DSRegistry<int> ::instance().ad dEntry("Third" , &i3);

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

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

}

Jul 23 '05 #1
3 2954
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 "Datastruct ure 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 "Datastruct ure 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 "Datastruct ure Registry" template-class as the "Registry
of Singletons" template-class.

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

typedef DSRegistry SingletonRegist ry;
typedef DSRegistry<clas s T> SingletonRegist ry<class T>;
typedef template DSRegistry<clas s T> template SingletonRegist ry<class
T>;
typedef DSRegistry<clas s T> template SingletonRegist ry<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 "Datastruct ure 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 "Datastruct ure 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 "Datastruct ure Registry" template-class as the "Registry
of Singletons" template-class.

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

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


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

Jul 23 '05 #3
Mr. Blackwell wrote:
typedef DSRegistry SingletonRegist ry;


What is DSRegistry? If It's a template you cannot typedef it like that.
typedef DSRegistry<clas s T> SingletonRegist ry<class T>;
typedef template DSRegistry<clas s T> template SingletonRegist ry<class
T>;
typedef DSRegistry<clas s T> template SingletonRegist ry<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 _SINGLETONREGIS TRY_H_
#define _SINGLETONREGIS TRY_H_

#include "DSRegistry .h"

template <class T>
class SingletonRegist ry : public DSRegistry<T>
{
};

#endif //_SINGLETONREGIS TRY_H_
///////////////////////////////////////////////
#include <iostream>

#include "SingletonRegis try.h"

using namespace std;

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

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

SingletonRegist ry<int>::instan ce().addEntry(" First" ,&i1);
SingletonRegist ry<int>::instan ce().addEntry(" Second" , &i2);
SingletonRegist ry<int>::instan ce().addEntry(" Third" , &i3);

int *val = SingletonRegist ry<int>::instan ce()("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
5410
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 the email address given.
4
4254
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 6.0-7.1).. Note, that basically I don't need an "extern C" linkage, I just need to define a type to cast a resolved function address.. Any ideas? Basically , I need something like this..
3
4674
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 T (*Type)();
2
1355
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 { char d; T o; }; #define A(T) (sizeof(a<T>) - sizeof(T)) template<int N> struct AS { char x; }; template<typename T> AS<A(T)> AF(T const &); #define AE(E) sizeof(AF(E)) int main(int n, char **) { return AE(n); }
5
2430
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 to his suggestion, I run into type inference problems when passing typedef templates as arguments to template functions. It seems the compiler (gcc 4.0) cannot resolve the typedef template with an instantiation of that typedef template. Below is...
4
2479
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 something like this: MyOtherClass<T> Type; but let's keep it simple for the moment */
9
3343
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
5
21156
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
1139
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 Func<float>(10,20); When I put float I get warning as “warning C4305: 'argument' : truncation from 'double' to 'float' “ , but I get the correct answer.
0
8631
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.