New Post. Hi all, I'm working on migrating my code from KCC to gcc, and I'm having some issues with "implicit typename" warnings from gcc. It's not implicit in class c1, so how come it's implicit in class c2? The problem is not correctable by adding typename to the offending line; this results in a compilation error.
Redefining the typedef in c2 removes the warning, but that makes the idea of public typedefs useless Does this behavior makes sense to people? Follow Post Reply. You need to add 'typename' to dependent names. This discussion thread is closed Start new discussion. Implicit conversion issue. You can use typedef declarations to construct shorter or more meaningful names for types already defined by the language or for types that you have declared.
Typedef names allow you to encapsulate implementation details that may change. In contrast to the class , struct , union , and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types. Names declared using typedef occupy the same namespace as other identifiers except statement labels. Therefore, they cannot use the same identifier as a previously declared name, except in a class-type declaration.
Consider the following example:. The name-hiding rules that pertain to other identifiers also govern the visibility of names declared using typedef. When declaring a local-scope identifier by the same name as a typedef, or when declaring a member of a structure or union in the same scope or in an inner scope, the type specifier must be specified. For example:. To reuse the FlagType name for an identifier, a structure member, or a union member, the type must be provided:. This declaration is taken to be an illegal declaration like.
You can declare any type with typedef, including pointer, function, and array types. You can declare a typedef name for a pointer to a structure or union type before you define the structure or union type, as long as the definition has the same visibility as the declaration. One use of typedef declarations is to make declarations more uniform and compact. To use typedef to specify fundamental and derived types in the same declaration, you can separate declarators with commas.
The following example provides the type DRAWF for a function returning no value and taking two int arguments:. The typedef declaration can be used to redeclare the same name to refer to the same type. Is there a better way to do this than what I've come up with so far? Yes, this will not generally work as you expect it. If a name does not depend on a template parameter it isn't searched there.
There is or may be a type with that name dependent on N. So no, you can't do what you want. Here are a few links that could help understand why it needs a typename keywords to be used:. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 11 years, 11 months ago.
Active 11 years, 11 months ago. Viewed 3k times.
0コメント