473,473 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Create 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>::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
8 1763
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>::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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
3
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()':...
11
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
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...
3
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:...
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: 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
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...
18
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.