If I have two templates that are mutually dependent, is there a way to declare one without defining it?

Recommended Answers

All 2 Replies

That's an interesting question. I've never done it myself before this, but this seems to work.

#include <windows.h>
#include <stdio.h>

template<class T> struct B ;

template<class T>
struct A
{
  B<T> b ;
  T    t ;
};

template<class T>
struct B
{
  T t;
};

int main()
{
  A<int> a ;
}

>If I have two templates that are mutually dependent, is there a way to declare one without defining it?
Yes, you can forward declare templates.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.