473,322 Members | 1,409 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,322 software developers and data experts.

typename

Hello,

In the following code-snippet,

template<class Base>

class Foo : public Base

{

typedef typename Base::Type Type; //1

Type FooBar();

};

template<class Base> typename Foo<Base>::Type //2

Foo<Base>::FooBar()

{

return 0;

}

struct Bar {typedef int Type;};

template class Foo<Bar>;

The C++ standard requires the typename at 1 but not at 2. However, the
compiler included in Visual Studio 2005 also requires typename at 2
resulting in a LOT of errors in my current project. Is this a known problem
that is scheduled to be fixed in the release version of VS2005?

Staffan Langin
Nov 17 '05 #1
13 1681
Staffan Langin wrote:
template<class Base>
class Foo : public Base {
typedef typename Base::Type Type; //1
Type FooBar();
};

template<class Base> typename Foo<Base>::Type //2
Foo<Base>::FooBar() { return 0; }
[...]
The C++ standard requires the typename at 1 but not at 2. However, the
compiler included in Visual Studio 2005 also requires typename at 2
resulting in a LOT of errors in my current project.


I'm not confident that you're correct about (2) being allowed by the
standard without a "typename" keyword. The type Foo<Base>::Type is clearly a
dependent type on the template parameter Base, and section 14.6.3 of the ISO
C++ standard says:

"A qualified-name that refers to a type and that depends on a
template-parameter (14.6.2) shall be prefixed by the keyword typename to
indicate that the qualified-name denotes a type, forming an
elaborated-type-specifier (7.1.5.3)."

Because Foo<Base>::Type is a qualified type name (it uses ::), this seems to
mandate the keyword. Paragraphs 5 and 6 reinforce this:

"The keyword typename shall only be used in template declarations and
definitions, including [...] in the return type for the definition of a
member function of a class template [...]" (this para allows but does not
require its use here)

"Within the definition of a class template or within the definition of a
member of a class template, [...] [t]he keyword typename shall always be
specified when the member is referred to using a qualified name, even if the
qualifier is simply the class template name."

For comparison, this (more or less) equivalent code compiles cleanly,
because it uses an unqualified type name, even though the type Type is still
dependent:

template<class Base>
class Foo : public Base {
typedef typename Base::Type Type;
Type FooBar() {
return 0;
}
};

It's possible that your previous compiler was more lenient, or
misinterpreted the standard; previous versions of Visual Studio did allow
one to omit this keyword (according to the MSDN entry for C4346). There
doesn't seem to be any ambiguity in leaving it out, since you can only have
a type name in that position, but the standard seems to require it, if I'm
not misinterpreting it. If you can justify your statement to the contrary
I'd like to hear your argument. I hope this helps.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 17 '05 #2
> It's possible that your previous compiler was more lenient, or
misinterpreted the standard; previous versions of Visual Studio did allow
one to omit this keyword (according to the MSDN entry for C4346). There
doesn't seem to be any ambiguity in leaving it out, since you can only
have a type name in that position, but the standard seems to require it,
if I'm not misinterpreting it. If you can justify your statement to the
contrary I'd like to hear your argument. I hope this helps.


Derrick,

If I interpret the defect report,
http://www.open-std.org/jtc1/sc22/wg...fects.html#224, correctly the
name at 2 is a member of the current instantiation and doesn't require the
typename keyword.

Staffan Langin
Nov 17 '05 #3
>In the following code-snippet,

template<class Base>
class Foo : public Base
{
typedef typename Base::Type Type; //1
Type FooBar();
};

template<class Base> typename Foo<Base>::Type //2
Foo<Base>::FooBar()
{
return 0;
}

struct Bar {typedef int Type;};
template class Foo<Bar>;
The C++ standard requires the typename at 1 but not at 2.
Staffan,

The Comeau online compiler seems to agree.
However, the
compiler included in Visual Studio 2005 also requires typename at 2
resulting in a LOT of errors in my current project. Is this a known problem
that is scheduled to be fixed in the release version of VS2005?


It's no different in the Aug CTP release, the compiler gives these
errors without typename:

warning C4346: 'Foo<Base>::Type' : dependent name is not a type
error C2143: syntax error : missing ';' before 'Foo<Base>::FooBar'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
fatal error C1903: unable to recover from previous error(s); stopping
compilation

I suggest that you report it as a bug here:

http://lab.msdn.microsoft.com/produc...k/default.aspx

and post a link back here to your bug report and I'll add a
confirmation vote to it.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #4
> I suggest that you report it as a bug here:

http://lab.msdn.microsoft.com/produc...k/default.aspx

and post a link back here to your bug report and I'll add a
confirmation vote to it.


David,

Thanks for your help. I've submitted a bug report now,

http://lab.msdn.microsoft.com/Produc...a-902187eae8b1

Staffan Langin
Nov 17 '05 #5
>Thanks for your help. I've submitted a bug report now,

http://lab.msdn.microsoft.com/Produc...a-902187eae8b1

I see Jonathan Caves has already replied to the report - I've added a
further note to see if he'll clarify this - it'd be nice to know that
he can reproduce it on an earlier build of the compiler, and that it's
now definitely resolved.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #6
> I see Jonathan Caves has already replied to the report - I've added a
further note to see if he'll clarify this - it'd be nice to know that
he can reproduce it on an earlier build of the compiler, and that it's
now definitely resolved.


If that's the case, I'd be very pleased. BTW, when can one expect the
release version of VS2005?

Staffan
Nov 17 '05 #7
>If that's the case, I'd be very pleased. BTW, when can one expect the
release version of VS2005?


I think it's been publically stated to be available sometime around
the beginning of Nov.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #8
Staffan Langin wrote:
It's possible that your previous compiler was more lenient, or
misinterpreted the standard; previous versions of Visual Studio did
allow one to omit this keyword (according to the MSDN entry for
C4346). There doesn't seem to be any ambiguity in leaving it out,
since you can only have a type name in that position, but the
standard seems to require it, if I'm not misinterpreting it. If you
can justify your statement to the contrary I'd like to hear your
argument. I hope this helps.


If I interpret the defect report,
http://www.open-std.org/jtc1/sc22/wg...fects.html#224, correctly
the name at 2 is a member of the current instantiation and doesn't
require the typename keyword.


I apologise - you're correct. I'm afraid I was misinterpreting this portion
of the standard. I hope the workaround of adding the keyword is sufficient
for your purposes (or that you're willing to wait for VS2005 to release).
Sorry about that.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 17 '05 #9
Derrick Coetzee [MSFT] wrote:
Staffan Langin wrote:
It's possible that your previous compiler was more lenient, or
misinterpreted the standard; previous versions of Visual Studio did
allow one to omit this keyword (according to the MSDN entry for
C4346). There doesn't seem to be any ambiguity in leaving it out,
since you can only have a type name in that position, but the
standard seems to require it, if I'm not misinterpreting it. If you
can justify your statement to the contrary I'd like to hear your
argument. I hope this helps.


If I interpret the defect report,
http://www.open-std.org/jtc1/sc22/wg...fects.html#224, correctly
the name at 2 is a member of the current instantiation and doesn't
require the typename keyword.


I apologise - you're correct. I'm afraid I was misinterpreting this
portion of the standard. I hope the workaround of adding the keyword
is sufficient for your purposes (or that you're willing to wait for
VS2005 to release). Sorry about that.


I see what happened now - after reading the item at
http://www.open-std.org/jtc1/sc22/wg...fects.html#224 , it seems
that my interpretation was based on the 1998 edition of the C++ standard,
which exhibited this issue. I'll be sure to refer to the most recent version
in the future. Sorry about that.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 17 '05 #10
Staffan Langin wrote:
I see Jonathan Caves has already replied to the report - I've added a
further note to see if he'll clarify this - it'd be nice to know that
he can reproduce it on an earlier build of the compiler, and that
it's now definitely resolved.


If that's the case, I'd be very pleased. BTW, when can one expect the
release version of VS2005?


Nov 7, 2005

-cd
Nov 17 '05 #11
David Lowndes wrote:
Thanks for your help. I've submitted a bug report now,

http://lab.msdn.microsoft.com/Produc...a-902187eae8b1

I see Jonathan Caves has already replied to the report - I've added a
further note to see if he'll clarify this - it'd be nice to know that
he can reproduce it on an earlier build of the compiler, and that it's
now definitely resolved.


I don't think it's fixed. Rather, I think Jonathan probably tried to
compile the code as-is, saw that it compiled, and assumed it was fixed (the
code as-posted has the extra 'typename' already).

I tested it on build 14.00.50727.24, which dates from less than a week ago
and nothing had changed.

I'd suggest re-activating the case on Product Feedback Center - although I'd
be very surprised if they fix it this late in the release cycle.

-cd
Nov 17 '05 #12
>I don't think it's fixed.

That was my suspicion too.
I tested it on build 14.00.50727.24, which dates from less than a week ago
and nothing had changed.
I've requested it be re-opened.
I'd suggest re-activating the case on Product Feedback Center - although I'd
be very surprised if they fix it this late in the release cycle.


Yeah, they won't even add pragamas to header files to eliminate
warnings that the new static analyser picks up on at this stage. :(

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #13
> I see what happened now - after reading the item at
http://www.open-std.org/jtc1/sc22/wg...fects.html#224 , it
seems that my interpretation was based on the 1998 edition of the C++
standard, which exhibited this issue. I'll be sure to refer to the most
recent version in the future. Sorry about that.


No prb. Actually, the defect report hasn't got TC1-status yet so formally
you are correct :-).

Staffan Langin
Nov 17 '05 #14

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

Similar topics

1
by: I wish | last post by:
I wrote some test code template <typename T> class A {}; class B{}; template < template <typename T> typename U > class C {}; int main( void )
2
by: Chris Foster | last post by:
Hi, I'm having some difficulty using types which are defined in a base class inside a derived class. The problem crops up using template classes. The following test code encapsulates what I'd...
1
by: lutorm | last post by:
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. Essentially, what happens is described by this example: ...
1
by: Carlos Martinez Garcia | last post by:
Hi all: I have the template class: template<typename InfoTabla> class TablaBusqueda { typename InfoTabla::Tabla TipoTabla; typename InfoTabla::Registro TipoRegistro; typename...
8
by: xuatla | last post by:
Hi, When I compile the following test code I got a warning about implicit typename. This happens in the member functions. Do you know the detail reason and solution? Thanks. - X ----------
1
by: ma740988 | last post by:
I'm wading my way through Josuttis template text. I'm having a hard time understanding some things. So given: template <class T> class generic_traits { public: typedef T value_type; };...
2
by: Dilip | last post by:
Folks I understand that the keyword typename is also used to indicate that a dependant parameter is a type. However I am a little unsure why I need typename in this following example: ...
7
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1)...
5
by: Jess | last post by:
Hello, I've seen two forms of template declarations template<typename T> class A{...}; and template<class T>
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.