473,480 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

typename D<T>::E e; // this->E would not be valid syntax

hi all:
I reading "C++ Templates: The Complete Guide "
Part II: Templates in Depth
he write:

template<typename T>
class B {
public:
enumE{e1=6,e2=28,e3=496};
virtual void zero(E e = e1);
virtual void one(E&);
};

template<typename T>
class D : public B<T{
public:
void f() {
typename D<T>::E e; // this->E would not be valid syntax
this->zero(); // D<T>::zero() would inhibit virtuality
one(e); // one is dependent because its argument
} // is dependent
};

who can tell me ,"this->E would not be valid syntax "
why?

Dec 12 '06 #1
4 1404
* lizhuo:
>
[with E a type]
who can tell me ,"this->E would not be valid syntax "
why?
this->SomeType is never valid syntax, because an object can't contain a
type: a class can contain a type, an object (instance of the class) can't.

--
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?
Dec 12 '06 #2
Alf P. Steinbach wrote:
* lizhuo:
>>
[with E a type]
who can tell me ,"this->E would not be valid syntax "
why?

this->SomeType is never valid syntax, because an object can't contain
a type: a class can contain a type, an object (instance of the class)
can't.
struct SomeType { int a; };
struct OtherType { double a; };
struct blah : SomeType, OtherType { void foo(); };

void blah::foo() {
this->SomeType ::a;
// ^^^^^^^^^^^^^^
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 12 '06 #3
lizhuo wrote:
hi all:
I reading "C++ Templates: The Complete Guide "
Part II: Templates in Depth
he write:

template<typename T>
class B {
public:
enumE{e1=6,e2=28,e3=496};
virtual void zero(E e = e1);
virtual void one(E&);
};

template<typename T>
class D : public B<T{
public:
void f() {
typename D<T>::E e; // this->E would not be valid syntax
this->zero(); // D<T>::zero() would inhibit virtuality
one(e); // one is dependent because its argument
} // is dependent
};

who can tell me ,"this->E would not be valid syntax "
why?
The operator-is called the member selection operator. It is used to
select a member (non-static method or variable) of an object. Thus
this->E is invalid, as E is not the name of a method or variable of
class D. As Victor pointed out, this->B::one would be legal, as B:: in
this expression is used to denote the name scope of class B for looking
up the member one (which would mean that you want to invoke the method
'one' as it is defined for class B).

Regards,
Stuart
Dec 12 '06 #4
* Victor Bazarov:
Alf P. Steinbach wrote:
>* lizhuo:
>>[with E a type]
who can tell me ,"this->E would not be valid syntax "
why?
this->SomeType is never valid syntax, because an object can't contain
a type: a class can contain a type, an object (instance of the class)
can't.

struct SomeType { int a; };
struct OtherType { double a; };
struct blah : SomeType, OtherType { void foo(); };

void blah::foo() {
this->SomeType ::a;
// ^^^^^^^^^^^^^^
}
:-) Yeah yeah, but, for other readers, that's "this->SomeType::a",
referring to a non-type.

Cheerio,

- Alf

--
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?
Dec 12 '06 #5

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

Similar topics

1
3258
by: Ian Pellew | last post by:
Hi All; Whats the xml way to have text include html type tags in? <Value> My text that will include <mytag> kjkjhkjh </mytag> </value> I am after shielding my text from the xml interpriter.
10
5374
by: Alexander Malkis | last post by:
What's the semantical/syntactical difference between two keywords "class" and "typename" (apart from different spelling)? -- Best regards, Alex. PS. To email me, remove "loeschedies" from...
1
1328
by: Dave | last post by:
Hello all, I have implemented a very simple generic hash table library. For those that are so inclined, I would like to request a critical review and comments. Is anything wrong? Could...
10
1667
by: NKOBAYE027 | last post by:
my friends, the end()... hehehe no...nothing so dire... I'm at an impasse I think. I've created the MathematicalSet class as follows - it has 4 lists. An ObjectPool of the actual objects, a...
2
2677
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
1740
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: ...
5
4445
by: narechk | last post by:
The following fails under VC8 Beta2: namespace A { // forward decl. template <typename Type, typename TypeX> bool foo(const Type&, const TypeX&); } // namespace A
13
1690
by: Staffan Langin | last post by:
Hello, In the following code-snippet, template<class Base> class Foo : public Base {
8
1764
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 ----------
7
2111
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)...
0
7046
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,...
1
6741
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...
1
4783
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
4485
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
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
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.