From: "Michael Kaes" <michael.kaes@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Template type usage from base classes
Date: Tue, 19 Aug 2008 15:37:00 -0000 [thread overview]
Message-ID: <9c1eb01c0808190834p147266b8w2ae6224ee49689b9@mail.gmail.com> (raw)
[-- 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;
}
next reply other threads:[~2008-08-19 15:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 15:37 Michael Kaes [this message]
2008-08-19 16:17 ` Eljay Love-Jensen
2008-08-19 16:17 ` Gian Lorenzo Meocci
2008-08-19 16:57 ` Michael Kaes
2008-08-19 23:54 ` Tom Browder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9c1eb01c0808190834p147266b8w2ae6224ee49689b9@mail.gmail.com \
--to=michael.kaes@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).