| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
January 06, 2006 What's wrong with this template? | ||||
|---|---|---|---|---|
| ||||
this code:
vvvvvvvv
class T(int i) // line 1
{
T!(i) dup()
{
return new T!(i);
}
}
void main()
{
T!(1) t = new T!(1);
}
^^^^^^^^
gives these errors:
(3): template instance T is not a template declaration, it is a class
(3): T!(1) is used as a type
(5): template instance T is not a template declaration, it is a class
(5): T!(1) is used as a type
(11): T!(1) is used as a type
What an I doing wrong?
| ||||
January 06, 2006 Re: What's wrong with this template? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> this code:
> vvvvvvvv
> class T(int i) // line 1
> {
> T!(i) dup()
> {
> return new T!(i);
> }
> }
>
> void main()
> {
> T!(1) t = new T!(1);
> }
Try this:
class T(int i) // line 1
{
T dup()
{
return new T();
}
}
void main()
{
T!(1) t = new T!(1);
}
| |||
January 06, 2006 Re: What's wrong with this template? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Thanks!!
Now, how about this:
class T(int i) // line 1
{
T!(i+1) inc()
{
return new T!(i+1)();
}
}
void main()
{
T!(1) t = new T!(1);
T!(2).T t2 = t.inc();
}
can you use a template inside it's self?
Sean Kelly wrote:
> BCS wrote:
>
>> this code:
>> vvvvvvvv
>> class T(int i) // line 1
>> {
>> T!(i) dup()
>> {
>> return new T!(i);
>> }
>> }
>>
>> void main()
>> {
>> T!(1) t = new T!(1);
>> }
>
>
> Try this:
>
> class T(int i) // line 1
> {
> T dup()
> {
> return new T();
> }
> }
>
> void main()
> {
> T!(1) t = new T!(1);
> }
| |||
January 06, 2006 Re: What's wrong with this template? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Thanks!!
>
> Now, how about this:
>
>
> class T(int i) // line 1
> {
> T!(i+1) inc()
Try .T!(i+1)
| |||
January 06, 2006 Re: What's wrong with this template? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | Ivan Senji wrote:
> BCS wrote:
>
>> Thanks!!
>>
>> Now, how about this:
>>
>>
>> class T(int i) // line 1
>> {
>> T!(i+1) inc()
>
>
> Try .T!(i+1)
BINGO, that's just what I needed!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply