472,372 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,372 software developers and data experts.

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>testAttribute::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,objc,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 1646
lo*********@googlemail.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...@mariani.wswrote:
lobequad...@googlemail.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>testAttribute::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>testAttribute::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*********@googlemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mariani.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...@mariani.wswrote:
lobequad...@googlemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mariani.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*********@googlemail.com wrote:
On Apr 26, 11:42 am, Gianni Mariani <gi3nos...@mariani.wswrote:
lobequad...@googlemail.com wrote:
On Apr 25, 10:34 am, Gianni Mariani <gi3nos...@mariani.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 objektorientierter Datenverarbeitung
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
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...
3
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...
6
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...
2
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...
10
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:...
0
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...
15
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...
5
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:...
9
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.