I have the following code which is unable to compile in VC6:
#include <iostream>
template<size_t target, size_t idx = 0>
struct _Iterator
{
enum
{
value = (target == idx) ? idx : _Iterator<targe t, idx+1>::value
};
};
int main()
{
std::cout << _Iterator<3>::v alue << std::endl;
// the expected result is 3
return 0;
}
The compilation error is
fatal error C1202: recursive type or function dependency context too
complex
This likely could be solved if I had switched to use VC7.1. However, I
have no luck that I must use VC6. Could anyone offer me a workaround?
Thanks in advance. 2 2051
Amon Tse wrote: I have the following code which is unable to compile in VC6: [...] This likely could be solved if I had switched to use VC7.1. However, I have no luck that I must use VC6. Could anyone offer me a workaround?
Please ask compiler-specific questions in the newsgroups dedicated to
those compilers (microsoft.publ ic.vc.language in this case).
"Amon Tse" <am*****@gmail. com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com I have the following code which is unable to compile in VC6:
#include <iostream>
template<size_t target, size_t idx = 0> struct _Iterator { enum { value = (target == idx) ? idx : _Iterator<targe t, idx+1>::value }; };
int main() { std::cout << _Iterator<3>::v alue << std::endl; // the expected result is 3 return 0; }
The compilation error is
fatal error C1202: recursive type or function dependency context too complex
This likely could be solved if I had switched to use VC7.1.
Actually no. You have an infinite loop. The problem is that in the line
value = (target == idx) ? idx : _Iterator<targe t, idx+1>::value
_Iterator<targe t, idx+1>::value is evaluated regardless of whether or not
target == idx.
However, I have no luck that I must use VC6. Could anyone offer me a workaround?
If you were using VC++7.1, you could do it this way:
#include <iostream>
template<size_t target, size_t idx = 0>
struct _Iterator
{
enum
{
value = _Iterator<targe t, idx+1>::value
};
};
template <size_t target>
struct _Iterator<targe t, target>
{
enum
{
value = target
};
};
This won't work for VC++6.0 since it doesn't support partial template
specialisation.
As for finding a workaround, it is not clear to me what your code is
attempting to do. Something far simpler like
template<size_t target>
struct _Iterator
{
enum
{
value = target
};
};
will produce an output of 3 from your code in main(). What more do you want?
--
John Carson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: SainTiss |
last post by:
Hi,
If you've got a template class with lots of methods,
and then you've got a type which works with the template,
except for one method...
What you need to do there is specialize the template for your
type. However, this requires you to copy the whole template, and
change the method, which leads to code duplication...
If there's only 1 template parameter, one can specialize the method
|
by: Senthilvel |
last post by:
Hi folks,
I was trying to learn the standard library algorithms where i got stuck with
the templates.
I wrote one function to eliminate the duplicates(from The C++ Programming
Language 3rd Edition)
template<class Con> void RemoveDuplicates(Con& seq)
{
sort(seq.begin(),seq.end());
|
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
----------
|
by: Jon Slaughter |
last post by:
I've managed to put together a template class that basicaly creates a
recursive tree that lets you easily specify the "base" class of that tree
and and ending notes and lets you stop the recursive process if you want.
The problem now is to make a Type list so I can specify more than one node
at a time to "attach" a class to. I think I will be able to handle this but
I want to run the code by you guys to see there are any major design...
|
by: mathieu |
last post by:
Hello there,
I am playing around with template metaprograming: I am trying to
redefines my own types. But I am facing a small issue, where I cannot
describe the whole implementation in one single class. Instead I have
to separate implementation for binary and ascii in two different
classes as I don't know how to use the traits technique for
constructors.
Any pointers very welcome !
| |
by: Mark Stijnman |
last post by:
I am trying to teach myself template metaprogramming and I have been
trying to create lists of related types. I am however stuck when I want
to make a template that gives me the last type in a list. I started by
using a linked list of types with templates like:
struct MyClass1 {};
struct MyClass2 {};
struct MyClass3 {};
struct NullType {};
|
by: Hendrik Schober |
last post by:
Hi,
suppose we have
template< typename T >
struct X;
and some specializations:
template<>
|
by: er |
last post by:
hi,
could someone please help with this code?
template<unsigned int N,unsigned int M>
class A{
public:
A();
};
|
by: andreyvul |
last post by:
I have a template function like this:
std::vector<std::pair<Square<T>, Triangle<T *
recarrow(T a, T b, int n) {
/* ... */
}
template <class T>
struct Square {
/* ... */
};
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |