473,761 Members | 8,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

implicit typename problem

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>::p tr_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>::p tr_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_t ype& 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
8 1777
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
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>::p tr_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>::p tr_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_t ype& 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
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_t ype, 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
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>::p tr_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>::p tr_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_t ype& 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
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_t ype, 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
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>::p tr_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>::p tr_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_t ype& 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_t ype getMemory(typen ame cBase<T>::ptr_t ype& p)

Best regards,

Tom

Jul 19 '06 #7
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_t ype, 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_t ype 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_t ype"... :p)
>
V
Jul 19 '06 #8
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::t ype 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::typ e 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_typ e;
};

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

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

Similar topics

1
3867
by: Steve Hill | last post by:
Hi, When compiling under g++ (version 3.2) the following code fragement gives me a warning: steve@khan:~/tmp> /opt/bin/g++ -o state_test state_test.cpp state_test.cpp:42: warning: `typename State<T>::State_change_counter' is implicitly a typename state_test.cpp:42: warning: implicit typename is deprecated, please see the documentation for details Any ideas why, and how to avoid it?
3
1658
by: Boris | last post by:
Hello, I have written a program that compiles just fine with GCC 3.3. With GCC 3.4.1 it results in this error: g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c .../Testp.c: In function `int main()': .../Testp.c:26: error: no match for 'operator<=' in 't <= 2.0e+0' Please help me, I have no idea where the problem is.
11
1877
by: Johan | last post by:
Hi Can somebody explain to me why I get this warning message and how I can solve this warning message. Thanks a lot Johan In member function `void
1
1860
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do implicit conversion for this case, however if instead of class X we just use a pointer then the implicit conversion will work. Anyone have any ideas why it will not do implicit conversion?
3
1893
by: Šimon Tóth | last post by:
Can anybody tell me how to turn of this warning? -Wno-deprecated doesn't work. I don't want to edit the source file, because it works fine and it's a bit hardcore stuff for me :) warning: implicit typename is deprecated, please see the documentation for details
1
1769
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: template <typename cell_data_type> class cell {}; template <typename a> class c1 { public: typedef cell<a> T_cell;
1
2151
by: pmatos | last post by:
Hi all, I'm starting to use templates and I just got a weird error which I was able to simplify into this code: #include <vector> using std::vector; template<class T> class foo {
3
1647
by: Brian Byrne | last post by:
I've recently developed a minor interest in Expression Templates and, in attempt to further my understanding of template metaprogramming, have been trying to create my own implementation. It seems I've ran into a problem that, while there are ways around it (causing way for code duplication), I'm not too sure if a direct solution exists. Given: template< typename T > class A { ... }; template< typename T >
18
2391
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.