By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,507 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

implicit typename problem

P: n/a
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

----------

test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details
test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details

-----------
// -- source code: test.cpp

#include <iostream>
using namespace std;

template <typename T>
class cBase
{
public:
typedef unsigned int size_type;
typedef T val_type;
typedef T* ptr_type;

public:
cBase()
{
// ...
} ;
} ;

template <class T>
class cDerived : public cBase<T>
{
public:
cDerived()
{
// ...
} ;
//line 28 here
ptr_type getMemory(ptr_type& p) // compiling warning: see above
{
return p;
} ;
} ;

int main()
{
cDerived<double>::size_type i = 0; // OK
cDerived<double>::val_type d = 0.1; // OK
cDerived<double>::ptr_type p = new double[10]; // OK

return 1;
}
Jul 19 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
xuatla wrote:
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.
This is covered in the FAQ. Look for "dependent names".
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 19 '06 #2

P: n/a
xuatla wrote:
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

----------

test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details
test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details

-----------
// -- source code: test.cpp

#include <iostream>
using namespace std;

template <typename T>
class cBase
{
public:
typedef unsigned int size_type;
typedef T val_type;
typedef T* ptr_type;

public:
cBase()
{
// ...
} ;
} ;

template <class T>
class cDerived : public cBase<T>
{
public:
cDerived()
{
// ...
} ;
//line 28 here
ptr_type getMemory(ptr_type& p) // compiling warning: see above
{
return p;
} ;
} ;

int main()
{
cDerived<double>::size_type i = 0; // OK
cDerived<double>::val_type d = 0.1; // OK
cDerived<double>::ptr_type p = new double[10]; // OK

return 1;
}
The FAQ answers this:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

I expect you'll find the rest of the FAQ quite helpful as well.

Best regards,

Tom

Jul 19 '06 #3

P: n/a
Victor Bazarov wrote:
xuatla wrote:
>>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.


This is covered in the FAQ. Look for "dependent names".

>>[..]


V
Thank you.

I read that part ([35.18], [35.19]) but still can't figure out the
solution for this problem. The one discussed in FAQ is about dependent
name of member functions, not on the typename. (for member function we
may change f() to this->f(), but for typename I have no idea and want to
get help).

I tried to use cBase<T>::ptr_type, but this is still warned as an
implicit typename.

One way I can solve it is to redefine ptr_type in the derived class. But
this looks not so efficient to me.

-X
Jul 19 '06 #4

P: n/a
Thomas Tutone wrote:
xuatla wrote:

>>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

----------

test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details
test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details

-----------
// -- source code: test.cpp

#include <iostream>
using namespace std;

template <typename T>
class cBase
{
public:
typedef unsigned int size_type;
typedef T val_type;
typedef T* ptr_type;

public:
cBase()
{
// ...
} ;
} ;

template <class T>
class cDerived : public cBase<T>
{
public:
cDerived()
{
// ...
} ;
//line 28 here
ptr_type getMemory(ptr_type& p) // compiling warning: see above
{
return p;
} ;
} ;

int main()
{
cDerived<double>::size_type i = 0; // OK
cDerived<double>::val_type d = 0.1; // OK
cDerived<double>::ptr_type p = new double[10]; // OK

return 1;
}


The FAQ answers this:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

I expect you'll find the rest of the FAQ quite helpful as well.

Best regards,

Tom
Thanks to Tom. Yes they are very helpful. I read through the whole FAQ
serveral times before. It seems that not many problems of STL have been
covered in FAQ so far. The reason I want to use typename is because I
want to write something close to STL.

-X
Jul 19 '06 #5

P: n/a
xuatla wrote:
Victor Bazarov wrote:
>xuatla wrote:
>>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.


This is covered in the FAQ. Look for "dependent names".

>>[..]


V
Thank you.

I read that part ([35.18], [35.19]) but still can't figure out the
solution for this problem. The one discussed in FAQ is about dependent
name of member functions, not on the typename. (for member function we
may change f() to this->f(), but for typename I have no idea and want
to get help).

I tried to use cBase<T>::ptr_type, but this is still warned as an
implicit typename.
Add 'typename' before it. For some reason I thought that the FAQ had
it. Lemme see... <looking ...Hmm. Missing. I'll need to contact
Marshall and see if we can add something.
One way I can solve it is to redefine ptr_type in the derived class.
You don't have to.
But this looks not so efficient to me.
What does efficiency have to do with it?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 19 '06 #6

P: n/a
xuatla wrote:
Thomas Tutone wrote:
xuatla wrote:

>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

----------

test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details
test.cpp:29: warning: `cDerived<T>::ptr_type' is implicitly a typename
test.cpp:29: warning: implicit typename is deprecated, please see the
documentation for details

-----------
// -- source code: test.cpp

#include <iostream>
using namespace std;

template <typename T>
class cBase
{
public:
typedef unsigned int size_type;
typedef T val_type;
typedef T* ptr_type;

public:
cBase()
{
// ...
} ;
} ;

template <class T>
class cDerived : public cBase<T>
{
public:
cDerived()
{
// ...
} ;
//line 28 here
ptr_type getMemory(ptr_type& p) // compiling warning: see above
{
return p;
} ;
} ;

int main()
{
cDerived<double>::size_type i = 0; // OK
cDerived<double>::val_type d = 0.1; // OK
cDerived<double>::ptr_type p = new double[10]; // OK

return 1;
}

The FAQ answers this:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

I expect you'll find the rest of the FAQ quite helpful as well.

Best regards,

Tom

Thanks to Tom. Yes they are very helpful. I read through the whole FAQ
serveral times before. It seems that not many problems of STL have been
covered in FAQ so far. The reason I want to use typename is because I
want to write something close to STL.

You're right - it is not as clear as it should be.

Change line 29 to:

typename cBase<T>::ptr_type getMemory(typename cBase<T>::ptr_type& p)

Best regards,

Tom

Jul 19 '06 #7

P: n/a
Victor Bazarov wrote:
xuatla wrote:
>>Victor Bazarov wrote:
>>>xuatla wrote:
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.
This is covered in the FAQ. Look for "dependent names".

[..]
V

Thank you.

I read that part ([35.18], [35.19]) but still can't figure out the
solution for this problem. The one discussed in FAQ is about dependent
name of member functions, not on the typename. (for member function we
may change f() to this->f(), but for typename I have no idea and want
to get help).

I tried to use cBase<T>::ptr_type, but this is still warned as an
implicit typename.


Add 'typename' before it. For some reason I thought that the FAQ had
it. Lemme see... <looking ...Hmm. Missing. I'll need to contact
Marshall and see if we can add something.
Thank you. With typename it works fine now.
>
>>One way I can solve it is to redefine ptr_type in the derived class.


You don't have to.
I agree. And I tried to add the following typedef in cDerived, then I
don't need to specify the scope again.

public:
typedef typename cBase<T>::ptr_type ptr_type;
>
>>But this looks not so efficient to me.


What does efficiency have to do with it?
I mean the coding efficiency... Sorry, I might be too lazy and greedy
(but writing "ptr_type" is easier than "typename cBase<T>::ptr_type"... :p)
>
V
Jul 19 '06 #8

P: n/a
Here's some code that might help clear it up for you. OTOH, it might
just make things worse. Good Luck!

#include <cstddef>
#include <ostream>
using namespace std;

struct
base_plain
{
typedef int type;
};

template< typename x >
struct
base_tpt
{
typedef x type;
};

template< typename x >
struct
derived_must
:
public base_tpt< x >
{
// need scope because base_tpt< x is a dependent type
// need typename because base_tpt< x >::type is a dependent type
typedef typename derived_must::type another_type;
};
template< typename x >
struct
derived_noneed
:
public base_plain
{
// don't need scope because base_plain is not a dependent type
// don't need typename because base_plain::type is not
// a dependent type
type another_type;

// don't need scope because base_plain is not a dependent type
// need typename because base_tpt< x >::type is a dependent type
typedef typename base_tpt< x >::type yet_another_type;
};

int
main()
{
}
Jul 20 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.