Why do I get the following error:
error: type 'std::vector<TO bject*, std::allocator< TObject*' is not
derived from type 'bar<TObject>'
with the following code:
#include <vector>
template<class TObject>
class bar
{
public:
typedef std::vector<TOb ject *ElemVector;
typedef std::vector<TOb ject *>::size_type size_type;
// I even wanted to write:
// typedef ElemVector::siz e_type size_type;
};
I guess this is something obvious?
Arne
--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---] 6 14983
Arne Schmitz wrote:
Why do I get the following error:
error: type 'std::vector<TO bject*, std::allocator< TObject*' is not
derived from type 'bar<TObject>'
with the following code:
#include <vector>
template<class TObject>
class bar
{
public:
typedef std::vector<TOb ject *ElemVector;
typedef std::vector<TOb ject *>::size_type size_type;
// I even wanted to write:
// typedef ElemVector::siz e_type size_type;
};
I guess this is something obvious?
bar<TObject>::E lemVector is a typedef for a dependent type. That is,
the type of ElemVector depends on the type of TObject. Therefore, when
you do ElemVector::siz e_type, the compiler doesn't know that size_type
is a type. You have to tell it with 'typename', like this:
#include <vector>
template<class TObject>
class bar
{
public:
typedef std::vector<TOb ject *ElemVector;
typedef typename ElemVector::siz e_type size_type;
};
Arne Schmitz wrote:
Why do I get the following error:
error: type 'std::vector<TO bject*, std::allocator< TObject*' is not
derived from type 'bar<TObject>'
with the following code:
#include <vector>
template<class TObject>
class bar
{
public:
typedef std::vector<TOb ject *ElemVector;
typedef std::vector<TOb ject *>::size_type size_type;
Make that:
typedef typename std::vector<TOb ject *>::size_type size_type;
// I even wanted to write:
// typedef ElemVector::siz e_type size_type;
};
I guess this is something obvious?
Not so obvious, but see this FAQ: http://www.parashift.com/c++-faq-lit...html#faq-35.18
Cheers! --M
Nate Barney wrote:
bar<TObject>::E lemVector is a typedef for a dependent type. That is,
the type of ElemVector depends on the type of TObject. Therefore, when
you do ElemVector::siz e_type, the compiler doesn't know that size_type
is a type.
And that always results in the oddest of errors. So far, the only
compiler I have worked with that informed you that you "need typename"
is g++.
"Nate Barney" <na********@gma il.comwrote in message
news:6N******** *************** *******@adelphi a.com...
Arne Schmitz wrote:
>Why do I get the following error:
error: type 'std::vector<TO bject*, std::allocator< TObject*' is not derived from type 'bar<TObject>'
with the following code:
#include <vector>
template<class TObject> class bar { public: typedef std::vector<TOb ject *ElemVector; typedef std::vector<TOb ject *>::size_type size_type; // I even wanted to write: // typedef ElemVector::siz e_type size_type; };
I guess this is something obvious?
bar<TObject>::E lemVector is a typedef for a dependent type. That is, the
type of ElemVector depends on the type of TObject. Therefore, when you do
ElemVector::siz e_type, the compiler doesn't know that size_type is a type.
You have to tell it with 'typename', like this:
#include <vector>
template<class TObject>
class bar
{
public:
typedef std::vector<TOb ject *ElemVector;
typedef typename ElemVector::siz e_type size_type;
};
You're right of course but this certainly seems like a deficiency in the
language:
// to compiler: ElemVector is a type
typedef std::vector<TOb ject *ElemVector;
// to compiler: ElemVector is STILL a type
typedef typename ElemVector::siz e_type size_type;
doh
Cy Edmunds wrote:
>
// to compiler: ElemVector is a type
typedef std::vector<TOb ject *ElemVector;
// to compiler: ElemVector is STILL a type
typedef typename ElemVector::siz e_type size_type;
That's not the issue. The typename refers to size_type, not to
ElemVector. The problem is that vector can be specialized for TObject*,
and the specialization might not provide size_type. So you have to tell
the compiler that you really mean it, and that it's an error if
vector<TObject* doesn't have a type named size_type.
--
-- Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." ( www.petebecker.com/tr1book)
mlimber wrote:
>typedef std::vector<TOb ject *ElemVector; typedef std::vector<TOb ject *>::size_type *size_type;
Make that:
typedef typename std::vector<TOb ject *>::size_type *size_type;
Thanks to everyone who answered. I *always* fall for this mistake. This time
it looks a bit different, but it is the same nevertheless... I guess I
still have to meditate over the semantics still a while.
Arne
--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tirath |
last post by:
Hi all,
I have a templated class that derives from a non-templated abstract class.
How do I then cast a base class pointer to a <templated> derived class
pointer in a generalised fashion?
Here's what I'm generally trying to achieve:
I'm building (trying to anyway) a serialization library. Here's my design:
|
by: Scott Brady Drummonds |
last post by:
Hi, everyone,
I've checked a couple of on-line resources and am unable to determine how
reinterpret_cast<> is different from static_cast<>. They both seem to
perform a compile-time casting of one type to another. However, I'm certain
that there is something else that is happening.
Can someone explain the difference or recommend an online site that can
explain it to me?
|
by: Grey Plastic |
last post by:
I have several classes that all keep track of static data. However,
the manner that they keep track of static data is identical, and so
I'm using the template<class Child> class Parent { ... }; idiom (don't
know the name of it, if there is one). The problem is that I don't
want any of my classes to have public constructors. They should be
created by a static member function.
This is what I want to do, save for the fact that this...
|
by: Alicia |
last post by:
Hello,
I am trying to figure out how to call an overloaded operator<<
inherited from a base class.
#ifndef PHONECALL
#define PHONECALL
#include "time.h"
#include "interval.h"
|
by: guru.slt |
last post by:
Hi,
see this code:
auto_ptr<int> int_auto_p(new int(3));
auto_ptr<int> int_auto_p2(int_auto_p.get());
Then, both auto_pointer will own the same object. That will violate the
single ownership expectation on auto_pointer.
| |
by: Mike Strieder |
last post by:
How can i get the text of the System.Type e.g. "base64Binary" from the .Net
type "byte"
I can not found any Function to give back this Schematype as string.
thx for your help
|
by: matty.hall |
last post by:
I have two classes: a base class (BaseClass) and a class deriving from
it (DerivedClass). I have a List<DerivedClass> that for various
reasons needs to be of that type, and not a List<BaseClass>. However, I
need to cast that list to a List<BaseClass> and it is not working. The
code is below. I get the following exception:
"Unable to cast object of type 'System.Collections.Generic.List`1' to
type 'System.Collections.Generic.List`1'."
...
|
by: Neil Zanella |
last post by:
Hello,
I would like to know what the difference is among the constructs
<%= %> for evaluating an expression and displaying the evaluated
result on the page and <%# %>. In particular I would like to know
why the <%# %> construct is necessary in locations where the other
<%= %> does not do. It seems to me that there is no equivalent of
the <%# %> construct in PHP, thus I thought I would post to
clarify. Is this an ASP.NET specific...
|
by: baltasarq |
last post by:
Hi, there !
When I use dynamic_cast for a single object, I do something like:
void foo(Base *base)
{
if ( dynamic_cast<Derived *>( base ) != NULL ) {
((Derived *) base)->do_something()
}
}
|
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...
|
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,...
| |
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...
|
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |