473,654 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::end l;
// use 'columns' and 'rows'
}
void out(){std::cout <<columns<<" "<<rows<<std::e ndl;};
};

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

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 2315
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::end l;
// use 'columns' and 'rows'
}
void out(){std::cout <<columns<<" "<<rows<<std::e ndl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"col umns, 200 CTOR"<<std::end l;
// 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::e ndl;};
};

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::end l;
// use 'columns' and 'rows'
}
void out(){std::cout <<columns<<" "<<rows<<std::e ndl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"col umns, 200 CTOR"<<std::end l;
// 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::e ndl;};
};

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.spa m> 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::end l;
// use 'columns' and 'rows'
}
void out(){std::cout <<columns<<" "<<rows<<std::e ndl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"col umns, 200 CTOR"<<std::end l;
// 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::e ndl;};
};

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.n ews.pas.earthli nk.net>,
Mike Wahler <mk******@mkwah ler.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.spa m> 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::end l;
// use 'columns' and 'rows'
}
void out(){std::cout <<columns<<" "<<rows<<std::e ndl;};
};

template <eTest1 EN1>
//template <int EN1>
class Image<EN1, et2_2> : private ImageBase
{
public:
Image()
{
rows=500;
std::cout<<"col umns, 200 CTOR"<<std::end l;
// 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::e ndl;};
};

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.spa m> wrote in message news:cs******** **@news.dtag.de ...
Mike Wahler wrote:
"Alex@L" <so***@no.spa m> 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
1959
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 {}; template<typename T, size_t n> struct B;
7
2374
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 searched the C++ FAQ Lite (web), the C++ newsgroups, "Thinking In C++" to no avail. Background ----------
13
2815
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 Solaris: class A { }; class B { }; template <typename Base> class Tpl : protected Base {
5
6578
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(); }; template<class T, unsigned N>
4
1848
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
6
2760
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 foo<true, T>(T val) { return(val); } But both gave no errors compiling this:
9
2764
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 template parameters at the call? Is the second assign() function really a specialization of the first assign() or is it an assign() overload? Thank you. -- Marek
9
1953
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 to templates when one of the two is specified... Exemple: template <class T, int Num> class A
10
2782
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 Tvoid A<T,1>::f (T) { } template <typename Tvoid A<T,3>::f (T) {
0
8290
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,...
0
8815
Oralloy
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...
0
8707
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...
1
8482
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,...
0
8593
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
7306
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...
0
5622
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
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.