By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,500 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,500 IT Pros & Developers. It's quick & easy.

Problem with Partial Template Specialization and Borland C++ Builder

P: n/a
I've a problem with following simple code (not really usefull):
//---------------------------------------------------------------------------
#pragma hdrstop
#include "stdio.h"
#include <iostream>

enum eTest1{et1_1, et1_2} e1;
enum eTest2{et2_1, et2_2} e2;
class ImageBase
{
public:
int rows;
int columns;
};
template <eTest1 EN1, typename eTest2 EN2>
//template <int EN1, typename eTest2 EN2>
class Image : private ImageBase
{
public:
Image()
{
rows=1;
columns=1;
std::cout<<"std CTOR"<<std::endl;
// use 'columns' and 'rows'
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"columns, 200 CTOR"<<std::endl;
// use 'columns' columns and 200 rows.
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

int main(int argc, char* argv[])
{
Image<et1_1, et2_1> img1;
img1.out();
Image<et1_1, et2_2> img2;
img2.out();
return 0;
}
//---------------------------------------------------------------------------
I't seem like the partial template specialization work not with my
Borland C++ Builder 5. I got the same behaviour with img1 and img2.
Some CTOR's and some out()-functions are called in both casses.
But if I use templates with ...int... it works fine.

Can somebody, please, explain me, what goes here wrong.

Thx, Alexander
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Alex@L wrote:
I've a problem with following simple code (not really usefull):
//---------------------------------------------------------------------------

#pragma hdrstop
#include "stdio.h"
#include <iostream>

enum eTest1{et1_1, et1_2} e1;
enum eTest2{et2_1, et2_2} e2;
class ImageBase
{
public:
int rows;
int columns;
};
template <eTest1 EN1, typename eTest2 EN2> ^^^^^^^^^^^^^^^^^^^
Isn't this supposed to be "eTest2 EN2" (without the 'typename')?
//template <int EN1, typename eTest2 EN2>
class Image : private ImageBase
{
public:
Image()
{
rows=1;
columns=1;
std::cout<<"std CTOR"<<std::endl;
// use 'columns' and 'rows'
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"columns, 200 CTOR"<<std::endl;
// use 'columns' columns and 200 rows.
That's misleading. First of all, it's 500 (FIVE hundred), not 200 (TWO
hundred). Second, 'columns' member is _uninitalised_.
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

int main(int argc, char* argv[])
{
Image<et1_1, et2_1> img1;
img1.out();
Image<et1_1, et2_2> img2;
img2.out();
return 0;
}
//---------------------------------------------------------------------------

I't seem like the partial template specialization work not with my
Borland C++ Builder 5. I got the same behaviour with img1 and img2.
Have you tried dropping the 'typename' keyword? Maybe it gets confused
by it and can't correctly generate the code...
Some CTOR's and some out()-functions are called in both casses.
But if I use templates with ...int... it works fine.

Can somebody, please, explain me, what goes here wrong.


Hard to say. VC++ calls different constructors and different 'out'.
Could be a bug.

V
Jul 22 '05 #2

P: n/a
Victor Bazarov wrote:
Alex@L wrote:
I've a problem with following simple code (not really usefull):
//---------------------------------------------------------------------------

#pragma hdrstop
#include "stdio.h"
#include <iostream>

enum eTest1{et1_1, et1_2} e1;
enum eTest2{et2_1, et2_2} e2;
class ImageBase
{
public:
int rows;
int columns;
};
template <eTest1 EN1, typename eTest2 EN2>
^^^^^^^^^^^^^^^^^^^
Isn't this supposed to be "eTest2 EN2" (without the 'typename')?


I've tried both, with and without 'typename'. That's have no difference.
//template <int EN1, typename eTest2 EN2>
class Image : private ImageBase
{
public:
Image()
{
rows=1;
columns=1;
std::cout<<"std CTOR"<<std::endl;
// use 'columns' and 'rows'
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"columns, 200 CTOR"<<std::endl;
// use 'columns' columns and 200 rows.

That's misleading. First of all, it's 500 (FIVE hundred), not 200 (TWO
hundred). Second, 'columns' member is _uninitalised_.


Right. But this simple class was only constructed to show the problem.
I've wrote above "(not really usefull)".
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

int main(int argc, char* argv[])
{
Image<et1_1, et2_1> img1;
img1.out();
Image<et1_1, et2_2> img2;
img2.out();
return 0;
}
//---------------------------------------------------------------------------

I't seem like the partial template specialization work not with my
Borland C++ Builder 5. I got the same behaviour with img1 and img2.

Have you tried dropping the 'typename' keyword? Maybe it gets confused
by it and can't correctly generate the code...


Yes. I've also tryed 'typedef'ed enums, 'class' (for abstract EN1 and
EN) and without all (i.e template<EN1, EN2>class...). In all cases I got
the same behaviour.
Some CTOR's and some out()-functions are called in both casses.
But if I use templates with ...int... it works fine.

Can somebody, please, explain me, what goes here wrong.

Hard to say. VC++ calls different constructors and different 'out'.
Could be a bug.

Thanks. I think also, that may be a bug. But another peoples assures,
this must work, but they give no working examples.
Jul 22 '05 #3

P: n/a

"Alex@L" <so***@no.spam> wrote in message news:cs**********@news.dtag.de...
Victor Bazarov wrote:
Alex@L wrote:
I've a problem with following simple code (not really usefull):
//--------------------------------------------------------------------------
-
#pragma hdrstop
#include "stdio.h"
#include <iostream>

enum eTest1{et1_1, et1_2} e1;
enum eTest2{et2_1, et2_2} e2;
class ImageBase
{
public:
int rows;
int columns;
};
template <eTest1 EN1, typename eTest2 EN2>


^^^^^^^^^^^^^^^^^^^
Isn't this supposed to be "eTest2 EN2" (without the 'typename')?


I've tried both, with and without 'typename'. That's have no difference.
//template <int EN1, typename eTest2 EN2>
class Image : private ImageBase
{
public:
Image()
{
rows=1;
columns=1;
std::cout<<"std CTOR"<<std::endl;
// use 'columns' and 'rows'
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"columns, 200 CTOR"<<std::endl;
// use 'columns' columns and 200 rows.

That's misleading. First of all, it's 500 (FIVE hundred), not 200 (TWO
hundred). Second, 'columns' member is _uninitalised_.


Right. But this simple class was only constructed to show the problem.
I've wrote above "(not really usefull)".
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

int main(int argc, char* argv[])
{
Image<et1_1, et2_1> img1;
img1.out();
Image<et1_1, et2_2> img2;
img2.out();
return 0;
}
//--------------------------------------------------------------------------
-
I't seem like the partial template specialization work not with my
Borland C++ Builder 5. I got the same behaviour with img1 and img2.

Have you tried dropping the 'typename' keyword? Maybe it gets confused
by it and can't correctly generate the code...


Yes. I've also tryed 'typedef'ed enums, 'class' (for abstract EN1 and
EN) and without all (i.e template<EN1, EN2>class...). In all cases I got
the same behaviour.
Some CTOR's and some out()-functions are called in both casses.
But if I use templates with ...int... it works fine.

Can somebody, please, explain me, what goes here wrong.

Hard to say. VC++ calls different constructors and different 'out'.
Could be a bug.

Thanks. I think also, that may be a bug. But another peoples assures,
this must work, but they give no working examples.


If you're convinced you have some code that is correct, yet
your compiler rejects it or doesn't create code that behaves
correctly, try another compiler (or two, or three). Many compilers
do have bugs.

One thing to try that has a good reputation for 'correctness'
is the Comeau 'try it' online compiler at www.comeaucomputing.com
(However, I hear they've been having some technical difficulties
with their web site, so this might not be possible at the moment).

-Mike
Jul 22 '05 #4

P: n/a
In article <xP***************@newsread3.news.pas.earthlink.ne t>,
Mike Wahler <mk******@mkwahler.net> wrote:
If you're convinced you have some code that is correct, yet
your compiler rejects it or doesn't create code that behaves
correctly, try another compiler (or two, or three). Many compilers
do have bugs.
Good advice. Furthermore, try other compilers _even when_ your
compiler behaves correctly.
One thing to try that has a good reputation for 'correctness'
is the Comeau 'try it' online compiler at www.comeaucomputing.com
(However, I hear they've been having some technical difficulties
with their web site, so this might not be possible at the moment).


More good advice :) For some people we never appeared down,
for those who found it down, it's been back up for sure since
Monday evening at the absolute latest (meaning for most people
it was back up before that). In short, internet seccurity was
breached (not for comeaucomputing.com, we were actually not
touched and up the whole time, but in the greater sense),
and hopefully the breach results in policy changes at ICANN.
We were not the only ones effected. For more details see
http://tinyurl.com/66rxz rather than discuss it here.
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 22 '05 #5

P: n/a
Mike Wahler wrote:
"Alex@L" <so***@no.spam> wrote in message news:cs**********@news.dtag.de...
Victor Bazarov wrote:
Alex@L wrote:
I've a problem with following simple code (not really usefull):

//--------------------------------------------------------------------------
-
#pragma hdrstop
#include "stdio.h"
#include <iostream>

enum eTest1{et1_1, et1_2} e1;
enum eTest2{et2_1, et2_2} e2;
class ImageBase
{
public:
int rows;
int columns;
};
template <eTest1 EN1, typename eTest2 EN2>

^^^^^^^^^^^^^^^^^^^
Isn't this supposed to be "eTest2 EN2" (without the 'typename')?


I've tried both, with and without 'typename'. That's have no difference.

//template <int EN1, typename eTest2 EN2>
class Image : private ImageBase
{
public:
Image()
{
rows=1;
columns=1;
std::cout<<"std CTOR"<<std::endl;
// use 'columns' and 'rows'
}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"columns, 200 CTOR"<<std::endl;
// use 'columns' columns and 200 rows.
That's misleading. First of all, it's 500 (FIVE hundred), not 200 (TWO
hundred). Second, 'columns' member is _uninitalised_.


Right. But this simple class was only constructed to show the problem.
I've wrote above "(not really usefull)".

}
void out(){std::cout<<columns<<" "<<rows<<std::endl;};
};

int main(int argc, char* argv[])
{
Image<et1_1, et2_1> img1;
img1.out();
Image<et1_1, et2_2> img2;
img2.out();
return 0;
}

//--------------------------------------------------------------------------
-
I't seem like the partial template specialization work not with my
Borland C++ Builder 5. I got the same behaviour with img1 and img2.
Have you tried dropping the 'typename' keyword? Maybe it gets confused
by it and can't correctly generate the code...


Yes. I've also tryed 'typedef'ed enums, 'class' (for abstract EN1 and
EN) and without all (i.e template<EN1, EN2>class...). In all cases I got
the same behaviour.

Some CTOR's and some out()-functions are called in both casses.
But if I use templates with ...int... it works fine.

Can somebody, please, explain me, what goes here wrong.
Hard to say. VC++ calls different constructors and different 'out'.
Could be a bug.


Thanks. I think also, that may be a bug. But another peoples assures,
this must work, but they give no working examples.

If you're convinced you have some code that is correct, yet
your compiler rejects it or doesn't create code that behaves
correctly, try another compiler (or two, or three). Many compilers
do have bugs.

One thing to try that has a good reputation for 'correctness'
is the Comeau 'try it' online compiler at www.comeaucomputing.com
(However, I hear they've been having some technical difficulties
with their web site, so this might not be possible at the moment).

-Mike

Many thanks, but the problem is, I MUST use this compiler at the
moment... Later it maybe newest C#, but also with binding to one comiler.

Alex
Jul 22 '05 #6

P: n/a
"Alex@L" <so***@no.spam> wrote in message news:cs**********@news.dtag.de...
Mike Wahler wrote:
"Alex@L" <so***@no.spam> wrote in message news:cs**********@news.dtag.de... If you're convinced you have some code that is correct, yet
your compiler rejects it or doesn't create code that behaves
correctly, try another compiler (or two, or three). Many compilers
do have bugs.

One thing to try that has a good reputation for 'correctness'
is the Comeau 'try it' online compiler at www.comeaucomputing.com
(However, I hear they've been having some technical difficulties
with their web site, so this might not be possible at the moment).

-Mike

Many thanks, but the problem is, I MUST use this compiler at the
moment...


I understand, and have been in a similar situation many times.
This is an example of what I call the "Welcome To The Real World"
syndrome. (I encounter it more often in the context of time and
budget issues, but I digress...)

If you have some correct code which your compiler cannot handle,
and are not allowed to use a different compiler, then you'll need
to create code to do the same thing using other language features
which your compiler does handle correctly. IMO being able to deal
with this kind of thing is what separates the 'men from the boys'
in "programmer-land." Remember that as a programmer, your primary
role is not writing code, but *solving problems*. Ideally, you're
creating something that uses a computer to solve someone else's
problem (e.g. keeping their books). But sometimes (or often),
during your act of creating, you encounter your *own* problems.
Use your skills. Solve the problem. Move on to the next.
[End lecture]. :-)

HTH,
-Mike
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.