Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

forward declaration of class using templates

Tags:

c++

g++

Can I use forward declaration for template class?
I try:

template<class que_type>
class que;
int main(){
    que<int> mydeque;
    return 0;
}
template<class que_type>
class que {};

I get:

error: aggregate 'que<int> mydeque' has incomplete type and cannot be defined.
like image 889
all Avatar asked Feb 06 '26 15:02

all


2 Answers

This is not a template issue. You cannot use a type as a by-value variable unless it has been fully defined.

like image 71
Oliver Charlesworth Avatar answered Feb 09 '26 09:02

Oliver Charlesworth


No. At the point of instantiation, the complete definition of the class template must be seen by the compiler. And its true for non-template class as well.

like image 40
Nawaz Avatar answered Feb 09 '26 09:02

Nawaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!