473,406 Members | 2,369 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,406 software developers and data experts.

Typedef'ing a subtype of a template

Hello.

It's been about a year since I last did some C++ programming. I am now
paying the price as I try to catch up with it.

The following is the initial snippet of a simple program I am working
on. I don't know or remember how one goes about typedef'ing a subtype of
a template.

#include <string>
#include <map>

namespace {
using namespace std;

typedef map<string, intWord_Map;
typedef Word_Map::value_type Word_Map_Pair;
}

The g++ compiler is not happy about the second typedef. I have tried
adding /typename/ to it, but the compiler then yells at me for using
/typename/ outside of a template.

Could anyone help a rusty fellow programmer?

Thank you,

--
Ney André de Mello Zunino
Nov 22 '07 #1
4 2053
Ney André de Mello Zunino wrote:
Hello.

It's been about a year since I last did some C++ programming. I am now
paying the price as I try to catch up with it.

The following is the initial snippet of a simple program I am working
on. I don't know or remember how one goes about typedef'ing a subtype of
a template.

#include <string>
#include <map>

namespace {
using namespace std;

typedef map<string, intWord_Map;
typedef Word_Map::value_type Word_Map_Pair;
}

The g++ compiler is not happy about the second typedef. I have tried
adding /typename/ to it, but the compiler then yells at me for using
/typename/ outside of a template.

Could anyone help a rusty fellow programmer?
I see nothing wrong with your code. Is this the entire fragment? What
compiler are you using?
Nov 22 '07 #2
Ney André de Mello Zunino wrote:
Hello.

It's been about a year since I last did some C++ programming. I am now
paying the price as I try to catch up with it.

The following is the initial snippet of a simple program I am working
on. I don't know or remember how one goes about typedef'ing a subtype of
a template.

#include <string>
#include <map>

namespace {
using namespace std;

typedef map<string, intWord_Map;
typedef Word_Map::value_type Word_Map_Pair;
}

The g++ compiler is not happy about the second typedef. I have tried
adding /typename/ to it, but the compiler then yells at me for using
/typename/ outside of a template.
How can it when you don't?

Post a complete example.

--
Ian Collins.
Nov 22 '07 #3
Alf P. Steinbach escreveu:
>namespace {
using namespace std;

typedef map<string, intWord_Map;
// typedef Word_Map::value_type Word_Map_Pair;

The commented definition would effectively define (note the const, which
makes the type non-assignable)

typedef pair< string const, int Word_Map_Pair;
I couldn't realize (remember) that the /map::value_type/ typedef is of
the form pair<const Key, T>. Thanks for pointing it out.
By the way, note that your naming convention is formally invalid.

An underscore can't be followed by an uppercase letter, it is reserved
for implementation names.
You know, I've always been a "camelCaser", of the kind who thought
underscores were really ugly. It was only *very* recently that I allowed
myself to have a different appreciation of underscores. The
experimentation is still in progress.

As for the implementation-reserved forms, I thought they concerned only
the cases where an uppercase letter follows an underscore at the
beginning of an identifier. But anyway, rusty as I am now, it's very
likely that I am missing something.
>int main(int argc, char* argv[]) {

Please don't include things such as unused arguments that cause warnings.

Aim for 100% clean compiles.
Sorry about that. The code posted is a trimmed-down version of a
slightly larger program where command line arguments are indeed used. I
just forgot to remove them here.
However, using the non-assignable version of Word_Map_Pair as a
container element type is formally Undefined Behavior, and a good
compiler + library implementation will then issue diagnostics.
Thanks, Alf. Got it now.

Cheers,

--
Ney André de Mello Zunino
Nov 22 '07 #4
Ney André de Mello Zunino wrote:
:: Alf P. Steinbach escreveu:
::
:::: namespace {
:::: using namespace std;
::::
:::: typedef map<string, intWord_Map;
:::: // typedef Word_Map::value_type Word_Map_Pair;
:::
::: The commented definition would effectively define (note the
::: const, which makes the type non-assignable)
:::
::: typedef pair< string const, int Word_Map_Pair;
::
:: I couldn't realize (remember) that the /map::value_type/ typedef
:: is of the form pair<const Key, T>. Thanks for pointing it out.
::
::: By the way, note that your naming convention is formally invalid.
:::
::: An underscore can't be followed by an uppercase letter, it is
::: reserved for implementation names.
::
:: You know, I've always been a "camelCaser", of the kind who thought
:: underscores were really ugly. It was only *very* recently that I
:: allowed myself to have a different appreciation of underscores. The
:: experimentation is still in progress.
::
:: As for the implementation-reserved forms, I thought they concerned
:: only the cases where an uppercase letter follows an underscore at
:: the beginning of an identifier.

You are correct.

Alf is probably mixing the rules up - a double underscore is reserved
anywhere in the identifier. Underscore uppercase only at the
beginning.

_Reserved_identifier
Reserved__identifier
Non_Reserved_Identifier
Bo Persson
Nov 22 '07 #5

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

Similar topics

0
by: Feldhaus | last post by:
Hello, I am working on the migration of our MFC Application written in VS C++ 6.0 to VS .Net 2003. I am getting an error I cannot solve, cause I am not firm with templates and class definitions....
1
by: James Aguilar | last post by:
Hey all, I ran into an interesting little problem with defining an iterator in a custom array class the other day. It goes something like this: template <typename T> class Array { public:...
3
by: James Aguilar | last post by:
Hey all, Another creative question: is it possible to do something like this to type define a pointer to a specific type of function: typedef bool (*)(std::string::const_iterator,...
7
by: Gurikar | last post by:
Does typedef vector<std::string> vNames; creates vector object?
3
by: Generic Usenet Account | last post by:
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...
4
by: pradosh | last post by:
Is it possible to typedef a template class? How? For example: template <class T> class OldClass { }; typedef OldClass<T> NewClass<T>;
2
by: Enrico Porreca | last post by:
Is the following a legal typedef? (gcc -Wall -ansi -pedantic says it's ok) typedef void Callback(void *obj); I mean "a Callback is a function taking void * and returning void" (not "a pointer...
0
by: PengYu.UT | last post by:
Hi, I'm wondering if it is possible to define typedef template? For example, I have template class A. I want give it an alias such as B. The problem comes from refactoring the code. Suppost A...
6
Markus
by: Markus | last post by:
Are there any major differences between the following, apart from syntactically: typedef struct { /** Struct members */ } stack; struct sstack { /** Struct members */ } stack;
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.