473,383 Members | 1,837 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,383 software developers and data experts.

Error referring to a template within a template - why?

Hi everyone,

I've come up against an issue with template types. Interestingly enough
it seems to trigger a bug in GCC 3.3.4 (it accepts the code but wrongly
replaces the typename), whereas Comeau's online compiler reports it as
an error.

Either way I don't quite understand what the problem is. If someone
could point it out for me, it would be much appreciated!

Comeau gives this error:

"ComeauTest.c", line 37: error: type name is not allowed
return createValueContainer<R>::DBType<DBT>::createAltVal ue(pField);
^

Of course if I take the error literally and remove the type name, it
tells me I need one:

"ComeauTest.c", line 37: error: argument list for class template
"createValueContainer<R>::DBType [with R=CProject]" is missing
return createValueContainer<R>::DBType::createAltValue(pF ield);
^

Whereas GCC accepts the code, but treats R == DBT, even though they're
not the same type. The compilable code is below.

Any suggestions as to where I'm going wrong?

Thanks,
Adam.
#include <string>

// Cut down datatypes to make this sample easier to read
class IValue {};
template <class R, typename T>
class TField {};

struct CProject {
struct Fields {
static TField<CProject, intTest;
};
};
TField<CProject, intCProject::Fields::Test;
template <class R>
struct createValueContainer {

template <typename DBT>
struct DBType {
template <typename T>
inline static IValue *createAltValue(const TField<R, T>& pField)
throw ()
{
// Do something with a variable of type DBT
return NULL;
}
};

};

template <typename DBT>
struct createAltValueContainer {
template <class R, typename T>
inline static IValue *createAltValue(const TField<R, T>& pField)
throw ()
{
// This next line doesn't seem to work. GCC gives an error and
// reports that R = std::string when it should be CProject.
return createValueContainer<R>::DBType<DBT>::createAltVal ue(pField);
}
};

int main(void)
{
createAltValueContainer<std::string>::createAltVal ue(
CProject::Fields::Test);
}
Oct 10 '07 #1
2 1731
> // This next line doesn't seem to work. GCC gives an error and
> // reports that R = std::string when it should be CProject.
return createValueContainer<R>::DBType<DBT>::createAltVal ue(pField);

What DBType is or isn't depends on the template parameter R.

You'll need to qualify with "template typename" or "typename template",
I don't recall the exact syntax but just look it up.

In short you need to tell the compiler what kind of beast DBType is.
Aha, that was it! I thought that was the problem but had no idea of the
syntax. Changing the line to this worked:

return createValueContainer<R>::template
DBType<DBT>::createAltValue(pField);

Thanks for your help!

Cheers,
Adam.
Oct 10 '07 #2
Adam Nielsen wrote:
Hi everyone,

I've come up against an issue with template types. Interestingly enough
it seems to trigger a bug in GCC 3.3.4 (it accepts the code but wrongly
replaces the typename), whereas Comeau's online compiler reports it as
an error.

Either way I don't quite understand what the problem is. If someone
could point it out for me, it would be much appreciated!

Comeau gives this error:

"ComeauTest.c", line 37: error: type name is not allowed
return createValueContainer<R>::DBType<DBT>::createAltVal ue(pField);
DBType is a template, and you need to tell the compiler:

createValueContainer<R>::template DBType<DBT>::createAltValue(pField);
^^^^^^^^^^^^^^^^^^^^

Of course if I take the error literally and remove the type name, it
tells me I need one:

"ComeauTest.c", line 37: error: argument list for class template
"createValueContainer<R>::DBType [with R=CProject]" is missing
return createValueContainer<R>::DBType::createAltValue(pF ield);
[snip]
Best

Kai-Uwe Bux
Oct 10 '07 #3

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

Similar topics

67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
1
by: Paulustrious | last post by:
Newbie using VC# Express..... Part the First ======== Can some one tell me why Example 1 compiles and Example 2 does not... Example 1 ------------ using System;
3
by: Filip Hendrickx | last post by:
Hi all. I am processing two documents with an XSLT, one is the input document, the other is loaded with the document() function in a variable $doc2. Inside a template that matches an element...
4
by: andrewcw | last post by:
I am moving some code forward from .NET 1.1. I was able to load the XSL file and perform the transform. The MSDN documentation looks like it should be easy. But I get a compile error. Ideas ?...
4
by: chris | last post by:
can anybody have some ideas?
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
8
by: Chuck B | last post by:
I just installed IIS 5.1 and Visual Studio 2003 with .NET 1.1. I'm having a problem starting an ASP.NET project. Everytime I select an template from the IDE I get the above message. I set up a...
3
by: John Shell | last post by:
Hello, all. The following code results in a C2666 error (2 overloads have similar conversions). class FSVec2D { public: FSVec2D() { // code omitted }
2
by: slizorn | last post by:
hi guys, i get the following error when i try to create a new TreeNode error C2514: 'TreeNode' : class has no constructors this error is caused by the following line:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.