473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with typelist-example on Visual Studio 2005

Hello all,

I've just read about typelists and their implementation in C++ using
templates in http://www.ddj.com/dept/cpp/184403813. Now my very first
test code using typelists does not compile...

I just cannot compile the example explained in the article on Visual
Studio 2005 or gcc 3.3.4 (to few template arguments). I would be glad,
if some template-guru among you could take a look at the source code
below and check, if I simply made any syntactic errors. I've checked
it twice, it is quite identical to the example printed in the article
referenced above. Nobody around here could make out any error. Am I
missing sth. here?

So this is the source code:

class null_typelist {};

template <class H, class T>
struct typelist
{
typedef H head;
typedef T tail;
};

template <class T1, class T2, class T3, class T4struct cons
{
typedef typelist<T1, typelist<T2, typelist<T3, typelist<T4,
null_typelist type;
};
template <class T1struct cons<T1, null_typelist, null_typelist,
null_typelist>
{
typedef typelist<T1, null_typelistty pe;
};
template <class T1, class T2struct cons<T1, T2, null_typelist,
null_typelist>
{
typedef typelist<T1, typelist<T2, null_typelist type;
};
template <class T1, class T2, class T3struct cons<T1, T2, T3,
null_typelist>
{
typedef typelist<T1, typelist<T2, typelist<T3, null_typelist >
type;
};

typedef cons<float, double>::type floating_point_ types;

int main(int argc, char * argv[])
{
return 0;
}

======== End of source code =============== =

This is the error message of Visual C++:

1>------ Build started: Project: test, Configuration: Debug Win32
------
1>Compiling...
1>templateTest. cpp
1>.\templateTes t.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>.\templateTes t.cpp(28) : error C2955: 'cons' : use of class template
requires template argument list
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>Build log was saved at "file://c:\TEMP\test\CM ake\TemplateTes ts
\test.dir\Debug \BuildLog.htm"
1>test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped
==========

======== End of VC++ error message =========

This is gcc 3.4.4's error message:

c:/TEMP/test/CMake/TemplateTests/templateTest.cp p:28: error: wrong
number of tem
plate arguments (2, should be 4)
c:/TEMP/test/CMake/TemplateTests/templateTest.cp p:11: error: provided
for `templ
ate<class T1, class T2, class T3, class T4struct cons'
c:/TEMP/test/CMake/TemplateTests/templateTest.cp p:28: error: `type'
does not nam
e a type
make[2]: *** [CMakeFiles/test.dir/templateTest.o] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2

======== End of gcc error message =========

Thanks for any hints or suggestions!

Cheers

Marco

Apr 3 '07 #1
2 2132
On Apr 3, 11:01 am, "Marco Wedekind" <m.w...@gmx.dew rote:
Hello all,

I've just read about typelists and their implementation in C++ using
templates inhttp://www.ddj.com/dept/cpp/184403813. Now my very first
test code using typelists does not compile...

I just cannot compile the example explained in the article on Visual
Studio 2005 or gcc 3.3.4 (to few template arguments). I would be glad,
if some template-guru among you could take a look at the source code
below and check, if I simply made any syntactic errors. I've checked
it twice, it is quite identical to the example printed in the article
referenced above. Nobody around here could make out any error. Am I
missing sth. here?

So this is the source code:

class null_typelist {};

template <class H, class T>
struct typelist
{
typedef H head;
typedef T tail;

};

template <class T1, class T2, class T3, class T4struct cons
{
typedef typelist<T1, typelist<T2, typelist<T3, typelist<T4,
null_typelist type;};

template <class T1struct cons<T1, null_typelist, null_typelist,
null_typelist>
{
typedef typelist<T1, null_typelistty pe;};

template <class T1, class T2struct cons<T1, T2, null_typelist,
null_typelist>
{
typedef typelist<T1, typelist<T2, null_typelist type;};

template <class T1, class T2, class T3struct cons<T1, T2, T3,
null_typelist>
{
typedef typelist<T1, typelist<T2, typelist<T3, null_typelist >
type;

};

typedef cons<float, double>::type floating_point_ types;

int main(int argc, char * argv[])
{
return 0;

}

======== End of source code =============== =

This is the error message of Visual C++:

1>------ Build started: Project: test, Configuration: Debug Win32
------
1>Compiling...
1>templateTest. cpp
1>.\templateTes t.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>.\templateTes t.cpp(28) : error C2955: 'cons' : use of class template
requires template argument list
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>Build log was saved at "file://c:\TEMP\test\CM ake\TemplateTes ts
\test.dir\Debug \BuildLog.htm"
1>test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped
==========

======== End of VC++ error message =========
Try adding default parameters to your initial class template
declaration. Either add a forward declaration like this:

template
<
class T1,
class T2 = null_typelist,
class T3 = null_typelist,
class T4 = null_typelist
>
struct cons;

above your first specialization of cons, or make the template
parameters in your initial definition have default parameters.

Cheers! --M

Apr 3 '07 #2
On 3 Apr., 17:43, "mlimber" <mlim...@gmail. comwrote:
On Apr 3, 11:01 am, "Marco Wedekind" <m.w...@gmx.dew rote:
Hello all,
I've just read about typelists and their implementation in C++ using
templates inhttp://www.ddj.com/dept/cpp/184403813. Now my very first
test code using typelists does not compile...
I just cannot compile the example explained in the article on Visual
Studio 2005 or gcc 3.3.4 (to few template arguments). I would be glad,
if some template-guru among you could take a look at the source code
below and check, if I simply made any syntactic errors. I've checked
it twice, it is quite identical to the example printed in the article
referenced above. Nobody around here could make out any error. Am I
missing sth. here?
So this is the source code:
class null_typelist {};
template <class H, class T>
struct typelist
{
typedef H head;
typedef T tail;
};
template <class T1, class T2, class T3, class T4struct cons
{
typedef typelist<T1, typelist<T2, typelist<T3, typelist<T4,
null_typelist type;};
template <class T1struct cons<T1, null_typelist, null_typelist,
null_typelist>
{
typedef typelist<T1, null_typelistty pe;};
template <class T1, class T2struct cons<T1, T2, null_typelist,
null_typelist>
{
typedef typelist<T1, typelist<T2, null_typelist type;};
template <class T1, class T2, class T3struct cons<T1, T2, T3,
null_typelist>
{
typedef typelist<T1, typelist<T2, typelist<T3, null_typelist >
type;
};
typedef cons<float, double>::type floating_point_ types;
int main(int argc, char * argv[])
{
return 0;
}
======== End of source code =============== =
This is the error message of Visual C++:
1>------ Build started: Project: test, Configuration: Debug Win32
------
1>Compiling...
1>templateTest. cpp
1>.\templateTes t.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>.\templateTes t.cpp(28) : error C2955: 'cons' : use of class template
requires template argument list
1 .\templateTest. cpp(11) : see declaration of 'cons'
1>Build log was saved at "file://c:\TEMP\test\CM ake\TemplateTes ts
\test.dir\Debug \BuildLog.htm"
1>test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped
==========
======== End of VC++ error message =========

Try adding default parameters to your initial class template
declaration. Either add a forward declaration like this:

template
<
class T1,
class T2 = null_typelist,
class T3 = null_typelist,
class T4 = null_typelist
>
struct cons;

above your first specialization of cons, or make the template
parameters in your initial definition have default parameters.

Cheers! --M
It works both ways and compiles :)

Cheers!

Marco

Apr 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2230
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application which makes calls to the service. We are using tcp channel which is using binaryformatter by default. The problem is that after a certain number of...
11
2490
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the Proxy class. template <typename T, typename P> class Container {
117
7113
by: Peter Olcott | last post by:
www.halting-problem.com
0
1442
by: Jon Slaughter | last post by:
I'm having a big problem(its probably simple but I just can't seem to figure it out). I have a Node template: template <unsigned int I, unsigned int J, typename T> struct Node { enum {i = I}; enum {j = J};
0
3638
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing problems have arisen. My investigations show that it is not related to the particular system I developed. but is affecting Access in general. So, has...
1
2421
by: John | last post by:
Hi, I tried to load a mixedmode dll (MC++) with AppDomain.Load(Byte ) in a C# Client. During the Load Process I got the following Exception: System.IO.FileLoadException: Ausnahme von HRESULT: 0x80131019. at System.Reflection.Assembly.nLoadImage(Byte rawAssembly, Byte rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark) at...
6
1571
by: Hendrik Schober | last post by:
Hi, I have a problem with extending some existing code. In a simplified form, the problem looks like this: I have four types, A, B, C, and D. Each A refers to zero, one, or more B's and each B can be child to zero, one, or more A's. I just call that "A is a parent of B", and "B is a child of A". The same goes for B and C and for C and D....
2
4536
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
3
2594
by: Isold.Wang | last post by:
I dont know how to use typelist.
1
2771
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare member variables with type "int" and "float". - I have a typelist and I want to declare a variable based on each of the types types. How can I...
0
7924
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. ...
1
7677
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...
0
7979
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...
0
6284
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
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...

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.