473,786 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

types of classes in template classes

Hello,

I am trying to get the following code work (unfortunately not
mine ... :( )

template <class Tclass Test {

public:

class ELEM;

class CONST_ITERATOR {

const Test<T>testAttr ibute::ELEM* elem;

It can be compiled with g++ 2.95.3. But

g++ -v
Using built-in specs.
Target: i686-apple-darwin8
Configured with: /private/var/tmp/gcc/gcc-5367.obj~1/src/configure --
disable-checking -enable-werror --prefix=/usr --mandir=/share/man --
enable-languages=c,obj c,c++,obj-c++ --program-transform-name=/^[cg]
[^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-
slibdir=/usr/lib --build=powerpc-apple-darwin8 --with-arch=nocona --
with-tune=generic --program-prefix= --host=i686-apple-darwin8 --
target=i686-apple-darwin8
Thread model: posix
gcc version 4.0.1 (Apple Computer, Inc. build 5367) complains with the
following error:
src/SlowNameToTMap. hh:23: error: type 'SLOW_NAME_TO_T _MAP<T>' is not
derived from type 'SLOW_NAME_TO_T _MAP<T>::CONST_ ITERATOR'

Any advice would be nice ... :)

Greetings,

lobequadrat

Apr 25 '07 #1
5 1748
lo*********@goo glemail.com wrote:
....
>
src/SlowNameToTMap. hh:23: error: type 'SLOW_NAME_TO_T _MAP<T>' is not
derived from type 'SLOW_NAME_TO_T _MAP<T>::CONST_ ITERATOR'

Any advice would be nice ... :)
A complete compilable (modulo the error) snippet would help in
understanding exactly what your problem is.
Apr 25 '07 #2
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
lobequad...@goo glemail.com wrote:

...
src/SlowNameToTMap. hh:23: error: type 'SLOW_NAME_TO_T _MAP<T>' is not
derived from type 'SLOW_NAME_TO_T _MAP<T>::CONST_ ITERATOR'
Any advice would be nice ... :)

A complete compilable (modulo the error) snippet would help in
understanding exactly what your problem is.
My problem is that I can't use "const Test<T>testAttr ibute::ELEM*
elem;"
to define a const of this type. When I try to make the type visible by
adding explicitly

class CONST_ITERATOR: SLOW_NAME_TO_T_ MAP<T>

the compiler complains that "ISO C++ forbids declaration of 'ELEM'
with no type".

The complete source should be ...

template <class Tclass Test {

public:

class ELEM;

class CONST_ITERATOR {

const Test<T>testAttr ibute::ELEM* elem;

};

class ELEM {

// whatever ...

}

};

The code compiled without an error with g++ 2.95.3 ... but not with a
current (see above) compiler ... ?

Apr 26 '07 #3
lo*********@goo glemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
....
The code compiled without an error with g++ 2.95.3 ... but not with a
current (see above) compiler ... ?
g++ 2.95.3 was buggy with templates. I wouldn't count on anything that
it accepted being valid.
Are either of these what you want ?

template <class Tclass Test {

public:

class ELEM;

class CONST_ITERATOR {

const typename Test<T>::ELEM * elem;
// note the "typename" keyword
};

class ELEM {

// whatever ...

};

};


template <class Tclass Testx {

public:

class ELEM;

class CONST_ITERATOR {

const ELEM * elem;

};

class ELEM {

// whatever ...

};

};
Apr 26 '07 #4
On Apr 26, 11:42 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
lobequad...@goo glemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
...
The code compiled without an error with g++ 2.95.3 ... but not with a
current (see above) compiler ... ?

g++ 2.95.3 was buggy with templates. I wouldn't count on anything that
it accepted being valid.
Ah ... ok - good to know ...
Are either of these what you want ?

template <class Tclass Test {

public:

class ELEM;

class CONST_ITERATOR {

const typename Test<T>::ELEM * elem;
// note the "typename" keyword
};

class ELEM {

// whatever ...

};

};

template <class Tclass Testx {

public:

class ELEM;

class CONST_ITERATOR {

const ELEM * elem;

};

class ELEM {

// whatever ...

};

};
Yepp - the first code snipped solved it ... as far as I understand c++
interprets this statement
"const typename Test<T>::ELEM * elem;" per default as a function and
"typename" changes this, that it is interpreted as a declaration?

Either way ... thanks for your help! :)

lobequadrat

Apr 27 '07 #5
lo*********@goo glemail.com wrote:
On Apr 26, 11:42 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
lobequad...@goo glemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mari ani.wswrote:
...
The code compiled without an error with g++ 2.95.3 ... but not with a
current (see above) compiler ... ?
g++ 2.95.3 was buggy with templates. I wouldn't count on anything that
it accepted being valid.
Ah ... ok - good to know ...
Actually, g++ 2.95.3 was very good with templates. The only
problem is that it is old; it implements templates as they were
defined when it appeared, and not as they are defined today.
Are either of these what you want ?
template <class Tclass Test {
public:
class ELEM;
class CONST_ITERATOR {
const typename Test<T>::ELEM * elem;
// note the "typename" keyword
};
class ELEM {
// whatever ...
};
};
[...]
Yepp - the first code snipped solved it ... as far as I understand c++
interprets this statement
"const typename Test<T>::ELEM * elem;" per default as a function and
"typename" changes this, that it is interpreted as a declaration?
The change is that orginally, all names in a template were bound
at the point of instantiation. At that point, the compiler
knows exactly what the name will be, and can treat it
appropriately. The language was changed so that a compiler can
parse and detect many errors in a template when the template is
defined, before any instantiation. This causes two changes in
code:

-- Names in templates are divided into dependent and
non-dependent names. Non-dependent names are completely
bound at the site of the template definition, and are not
looked up again at the site of instantiation. This
typically affects functions which the template author
expects to resolve to a function in a dependent base
class---given something like:

template< typename Toto >
class C : public Toto
{
public:
void f()
{
g() ; // should resolve to Toto::g()...
}
} ;

Because there is nothing in the above code to let the
compiler know that g() is dependent, the compiler tries to
resolve it at the definition site, doesn't find a g(), and
complains (or finds a g(), and that is the function which
will be called, and not the one in the base class). Writing
the call this->g() forces the compiler to consider the name
dependent, and defers resolution until instantiation.

-- It is, regretfully, impossible to correctly parse C++
without knowing which names name types, and which don't.
The same thing holds for templates. For non-dependent
names, this is no problem; the compiler knows what they name
at the definition site. For dependent names, however, it is
a problem, since this information isn't available until
later. The decision taken is that a dependent name will be
assumed to be neither a type nor a template unless you tell
the compiler otherwise. In your code, for example, the
compiler originally assumed that ELEM in Test<T>::ELEM (a
dependent name, since it obviously depends on Test<T>, which
depends on T) is not a type nor a template. Except that in
this case, the declaration is illegal if it isn't. By
adding the keyword typename, you tell the compiler that it
is a type name. Similar situations can occur (albeit much
more rarely) with templates: if the orginal programmer of C,
above, expected g to be a template function, and wrote:
this->g<int>() ;
the compiler would assume at the definition site that the <
was the less than token, which would result in an error. In
such cases, you have to write:
this->template g<int>() ;
so the compiler knows that g will name a template, and that
the < starts the argument list.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 27 '07 #6

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

Similar topics

2
2699
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 like to do, but doesn't compile with g++ (v3.3.3). //--------------------------------------------------------- // A = base class template <typename T>
3
1627
by: Ruben Campos | last post by:
I've found a problem with types defined inside a template. With a non-template class, I can write the following: // MyClass.hpp class MyClass { // ... typedef unsigned int MyType; MyType MyMethod ( /* ... */ ); // ...
6
1808
by: Code4u | last post by:
I need to design data storage classes and operators for an image processing system that must support a range of basic data types of different lengths i.e. float, int, char, double. I have a template class that stores the data. The problem with this design is the inability to treat image data generically- I have a set of specialized classes with no connection. I'm considering deriving all ImageData<T> classes from a image data abstract base...
2
1334
by: Herby | last post by:
I need to define my own types and arrays of these types. These types are for the most part extensions of the built in types and need to provide all the basic operations of arithmetic and relational. If i was using C++ I would overload the operators against my types and use STL Vector etc. No problem. No performance costs. No virtual functions, no casting etc.
10
10224
by: mast2as | last post by:
Is it possible to limit a template class to certain types only. I found a few things on the net but nothing seems to apply at compile time. template <typename T> class AClass { public: AClass() {} };
0
2033
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid this topic getting lost before people interested in the problem notice it. The important tricks to the solution are two: 1) make the custom classes take a TEMPLATE argument which defines their BASE class 2) EMBED the custom classes in a "Traits"...
15
3537
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and you want to make a deque which can contain any objects of any of those types. Normally what you would have to do is to make a deque or vector of pointers of the base class type and then allocate each object dynamically with 'new' and store the...
5
2575
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so: const char *s = string_mapper<thetype>(); However I do not know the string to be associated with the type at compile time, and will need a way to set up the mapping, to be created at run time, possibly like so: void foo(char*...
9
1701
by: Ben Rudiak-Gould | last post by:
Background: I have some structs containing std::strings and std::vectors of other structs containing std::strings and std::vectors of .... I'd like to make a std::vector of these. Unfortunately the overhead of the useless copies made each time the vector is resized is too large for me to ignore. I know that rvalue references fix this problem, but I don't think they'll be widely available for years and I need something that works now....
0
10163
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...
0
9960
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 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...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
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
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
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...
1
4064
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
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.