Re: nesting typename or class member
* zade:
As we know, if we want to define a dependent type in class template or
function template, we have to use typename keyword; but if you
reference a class field, it doesn't need that keyword.
Not sure what you mean by "class field". If something is a type then
'typename' is applicable, if not, then 'typename' is not applicable.
My problem is that when I use nesting typename or class member , it
compiles error in MSVC2005, but succeed in GCC3.2.4. Codes like
below:
typedef typename my_traints<typename
std::iterator_traits<TypeIterator>::value_type>::my_type::nesting_type
nesting_type;
nesting_type & v = my_traints<typename
std::iterator_traits<TypeIterator>::value_type>::my_type::nesting_value;
Please post a complete, small program that illustrates the problem.
See the FAQ item titled "How do I post a question about code that
doesn't work correctly?", currently available at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.
And please copy and paste that code (no manual typing), with tabs
converted to spaces.
Example:
#include <iostream>
#include <ostream>
#include <iterator>
struct MyType
{
typedef int nesting_type;
static int nesting_value;
};
int MyType::nesting_value = 42;
template< typename T >
struct my_traints
{
typedef MyType my_type;
};
template< typename TypeIterator >
struct Foo
{
typedef typename my_traints<
typename std::iterator_traits<TypeIterator>::value_type
>::my_type::nesting_type
nesting_type;
void bar()
{
nesting_type & v = my_traints<
typename std::iterator_traits<TypeIterator>::value_type
>::my_type::nesting_value;
std::cout << v << std::endl;
}
};
int main()
{
Foo<char*> o;
o.bar();
}
But it dosen't always compile error in MSVC2005. So I am very confused
about this.
Does anyone have such problems like this?
Yes.
Thanks!
You're welcome.
Hth.,
- Alf
%% The campaign to answer articles with no follow-ups so far.
%% Posted 12.05.2007 07:20 (my articles often linger in the queue since
%% I can't process my own articles, hence the datetime stamp).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]