Skip to content

Instantly share code, notes, and snippets.

@asquared
Created April 5, 2013 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asquared/5315641 to your computer and use it in GitHub Desktop.
Save asquared/5315641 to your computer and use it in GitHub Desktop.
More fun with non-working templates.
template <typename T>
class B {
};
template <typename T>
class A {
public:
template <typename U> B<U> *alloc_B( );
};
template <typename T> template <typename U>
B<U> *A<T>::alloc_B( ) {
return new B<U>( );
}
#ifdef BREAK
template <typename T>
class C {
public:
template <typename U> void x(B<U> &b) {
A<U> tmp;
B<U> *tmp2;
tmp2 = tmp.alloc_B<U>( );
delete tmp2;
}
};
#endif
int main( ) {
A<int> a;
B<float> *bp = a.alloc_B<float>( );
delete bp;
#ifdef BREAK
C<int> c;
B<float> b;
c.x(b);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment