* Template type usage from base classes
@ 2008-08-19 15:37 Michael Kaes
2008-08-19 16:17 ` Gian Lorenzo Meocci
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Michael Kaes @ 2008-08-19 15:37 UTC (permalink / raw)
To: gcc-help
[-- Attachment #1: Type: text/plain, Size: 1798 bytes --]
Hi,
I am having some problems with a template structure I am using and was
hoping that someone around here could give me a hint. The code I am
using works fine on the Visual Studio 8 compiler from MS but it does
not compile on the gcc.
I stripped it down as good as I could and it looks valid to me but
still it only compiles with VS8 and not with the GCC. The interesting
thing is that it does work when I only use one template parameter.
I am using gcc version 4.2.4 (Debian 4.2.4-3). Could this be a bug in
the gcc or is this simply not valid c++ code and the VS8 is only
generous?
The stripped down example:
#include<iostream>
template<
size_t sizeValue,
typename NumericType>
class Base
{
protected:
NumericType n;
public:
typedef NumericType val_t;
Base(val_t t):n(t)
{
}
};
template<
size_t sizeValue,
typename unusedType
>
class Derived;
template<
size_t sizeValue
>
class Derived<sizeValue, int> : public Base<sizeValue, int>
{
public:
Derived() : Base<sizeValue, val_t>(1)
{
}
};
int main()
{
Derived<12, int> d;
}
The error message I get is the following
templateTest.cpp: In constructor Derived<sizeValue, int>::Derived():
templateTest.cpp:32: error: val_t was not declared in this scope
templateTest.cpp:32: error: template argument 2 is invalid
templateTest.cpp: In constructor Derived<sizeValue, int>::Derived()
[with unsigned int sizeValue = 12u]:
templateTest.cpp:39: instantiated from here
templateTest.cpp:32: error: no matching function for call to Base<12u,
int>::Base()
templateTest.cpp:13: note: candidates are: Base<sizeValue,
NumericType>::Base(NumericType) [with unsigned int sizeValue = 12u,
NumericType = int]
templateTest.cpp:7: note: Base<12u, int>::Base(const
Base<12u, int>&)
Thanks in advance
Michael Kaes
[-- Attachment #2: templateIssue.cpp --]
[-- Type: text/plain, Size: 483 bytes --]
#include<iostream>
template<
size_t sizeValue,
typename NumericType>
class Base
{
protected:
NumericType n;
public:
typedef NumericType val_t;
Base(val_t t):n(t)
{
}
};
template<
size_t sizeValue,
typename unusedType
>
class Derived;
template<
size_t sizeValue
>
class Derived<sizeValue, int> : public Base<sizeValue, int>
{
public:
Derived() : Base<sizeValue, val_t>(1)
{
}
};
int main()
{
Derived<12, int> d;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Template type usage from base classes
2008-08-19 15:37 Template type usage from base classes Michael Kaes
@ 2008-08-19 16:17 ` Gian Lorenzo Meocci
2008-08-19 16:17 ` Eljay Love-Jensen
2008-08-19 16:57 ` Michael Kaes
2 siblings, 0 replies; 5+ messages in thread
From: Gian Lorenzo Meocci @ 2008-08-19 16:17 UTC (permalink / raw)
To: Michael Kaes; +Cc: gcc-help
Try to add
typedef typename Base<sizeValue, int>::val_t val_t;
after
Derived() : Base<sizeValue, val_t>(1)
{
}
--
Gian Lorenzo Meocci
http://www.meocci.it
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Template type usage from base classes
2008-08-19 15:37 Template type usage from base classes Michael Kaes
2008-08-19 16:17 ` Gian Lorenzo Meocci
@ 2008-08-19 16:17 ` Eljay Love-Jensen
2008-08-19 16:57 ` Michael Kaes
2 siblings, 0 replies; 5+ messages in thread
From: Eljay Love-Jensen @ 2008-08-19 16:17 UTC (permalink / raw)
To: Michael Kaes, GCC-help
Hi Michael,
Try this...
template<
size_t sizeValue
>
class Derived<sizeValue, int> : public Base<sizeValue, int>
{
public:
Derived() : Base<sizeValue, typename Base<sizeValue, int>::val_t>(1)
{
}
};
Microsoft's compiler is in error, it should not accept your non-compliant
code.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Template type usage from base classes
2008-08-19 15:37 Template type usage from base classes Michael Kaes
2008-08-19 16:17 ` Gian Lorenzo Meocci
2008-08-19 16:17 ` Eljay Love-Jensen
@ 2008-08-19 16:57 ` Michael Kaes
2008-08-19 23:54 ` Tom Browder
2 siblings, 1 reply; 5+ messages in thread
From: Michael Kaes @ 2008-08-19 16:57 UTC (permalink / raw)
To: gcc-help
Thanks everybody,
works as it I expected it :-)
Took me nearly a day. I should stick more to gcc than to VS8.
Regards
Michael Kaes
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Template type usage from base classes
2008-08-19 16:57 ` Michael Kaes
@ 2008-08-19 23:54 ` Tom Browder
0 siblings, 0 replies; 5+ messages in thread
From: Tom Browder @ 2008-08-19 23:54 UTC (permalink / raw)
To: Michael Kaes; +Cc: gcc-help
On Tue, Aug 19, 2008 at 11:44 AM, Michael Kaes <michael.kaes@gmail.com> wrote:
> Thanks everybody,
>
> works as it I expected it :-)
> Took me nearly a day. I should stick more to gcc than to VS8.
I've had similar experiences with a cross-platform project where my
coworker is doing the Windows part and I'm doing the Linux part.
I get gcc-4.3.1 warnings and errors that he doesn't get *until* he
uses the /Za argument to his MSVC++ 2005 compiler.
-Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-08-19 23:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-19 15:37 Template type usage from base classes Michael Kaes
2008-08-19 16:17 ` Gian Lorenzo Meocci
2008-08-19 16:17 ` Eljay Love-Jensen
2008-08-19 16:57 ` Michael Kaes
2008-08-19 23:54 ` Tom Browder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).