472,331 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Problem with Partial Template Specialization and Borland C++ Builder

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
6 2196
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
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

"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TT \(Tom Tempelaere\) | last post by:
Comeau compiler complains (too few arguments for class template "B") at line *** #include <memory> template<typename T, size_t n> struct A...
7
by: Thomas Matthews | last post by:
Hi, I am converting my table and record classes into templates. My issue is the syntax of declaring a friend class within the template. I have...
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func();...
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function...
9
by: Greg | last post by:
Hi, I would like to specify behavior of a class member relatively to template implemetation. It works in usual cases but it seems to fail with...
10
by: jason.cipriani | last post by:
I never seem to be able to get this right. Here I have some code: template <typename T, int Nclass A { void f (T); }; template <typename...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.