🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Ken Rice Tue, 27 Feb 1996 02:07
Is this legal?
#3515
Author: Ken Rice
Date: Tue, 27 Feb 1996 02:07
43 lines
1894 bytes
template < class ItemType > class T
{
public:
    T(){}
    virtual ~T(){}
    ItemType mArr;
};

void main(void)
{
    T<int>* pA = nil;
    dynamic_cast < T<int>* > (pA);
}

Our compiler reports this error:
Error   : illegal use of incomplete struct/union/class
x.cp line 12   dynamic_cast < T<int>* > (pA);

Note that T<int> is not used in a way that causes it to be instantiated until
it gets to the dynamic_cast. The april 95 draft sec 5.2.6 [expr.dynamic.cast]
says "Types shall not be defined in a dynamic_cast."

So, the question is, does using a template that has not been instantiated
before count as 'defining a type' (as the compiler seems to think), or is
the code legal?

The example can be made to compile by gratuitously declaring a variable of
type T<int> before the dynamic_cast line to force implicit instantiation,
but that seems a bit kludgy.

Thanks,
Ken Rice.

-- 
Ken Rice
rice@tiac.net
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Re: Is this legal?
#3529
Author: David Byrden
Date: Wed, 28 Feb 1996 00:17
30 lines
1421 bytes
>>>>>>>
void main(void)
{
    T<int>* pA = nil;
    dynamic_cast < T<int>* > (pA);
}

Our compiler reports this error:
Error   : illegal use of incomplete struct/union/class
x.cp line 12   dynamic_cast < T<int>* > (pA);
<<<<<<<<<<


  Your compiler is not in agreement with the January 1996 draft standard, 
and I quote;



5.2.6.3  If the type of [the pointer] is the same as the required result 
type........the result is v (converted if necessary).


                                        David
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads