473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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_typelisttype;
};
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>.\templateTest.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest.cpp(11) : see declaration of 'cons'
1>.\templateTest.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\CMake\TemplateTests
\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.cpp:28: error: wrong
number of tem
plate arguments (2, should be 4)
c:/TEMP/test/CMake/TemplateTests/templateTest.cpp:11: error: provided
for `templ
ate<class T1, class T2, class T3, class T4struct cons'
c:/TEMP/test/CMake/TemplateTests/templateTest.cpp: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 2120
On Apr 3, 11:01 am, "Marco Wedekind" <m.w...@gmx.dewrote:
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_typelisttype;};

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>.\templateTest.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest.cpp(11) : see declaration of 'cons'
1>.\templateTest.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\CMake\TemplateTests
\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.dewrote:
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_typelisttype;};
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>.\templateTest.cpp(28) : error C2976: 'cons' : too few template
arguments
1 .\templateTest.cpp(11) : see declaration of 'cons'
1>.\templateTest.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\CMake\TemplateTests
\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
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...
11
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...
117
by: Peter Olcott | last post by:
www.halting-problem.com
0
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 =...
0
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...
1
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...
6
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...
2
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...
3
by: Isold.Wang | last post by:
I dont know how to use typelist.
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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,...
0
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...

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.