   C++ Template
class A{ //a few things that dont matter};class B{//a few things that dont matter};class C{//a few things that dont matter};class D{//a few things that dont matter};template< class T >T* forest::Create( int& elements, T* original) {    T* temp = new T[elements+1];if (elements > 0)std::copy(original, original + elements, temp);    ++elements;    return temp;}2 questions, in this function is it possible to compare the template type T with the actual type being passed through the function? that is if the type of original is equal to *A. ex. if (original == A)Second question, can i include a similar type of 'template' but instead of using it for a function, using it for variables inside of a class. Because Id rather have 1 pointer, that points the either *A, *B, *C, or *D than 4 different types (A,B,C,D) pointers because only 1 type (A,B,C,D) should have something pointing to it at one time.. If anyone can understand what Im saying if not ill try to explain more.   
  to answer your second question first: sure, you can use templates in classes. take a look at stl (standard library) for several useful examples (vector,set,...).to answer your first question (i am not sure that i understood it but here goes): when you use a template the compiler will actually generate separate functions for each template class. this means that when using the same template function with int and long for example the compiler will automatically generate two seperate functions. one for int and one for long. when you call this function with different parameter types you are actually calling two different functions. i thing that this makes the question irrelevent.   ;  yeah but in your code for the function, how can you tell what type the parameter is if its just type template.I want to know if i can tell the type being passed into it, inside the function.This is what I mean for the second question.struct myclass_spot{template< class S>S* s; //points to 1 of 4 different types of objects};I want something that points to 1 of the 4 different types of objects. So I can change it for example.A* a = new A[10];B* b = new B[10];s = a; // or later on i could set s to b;;  typeid, dynamic_cast, specialization, or via polymorphism (or using polymorphic behavior and dynamic dispatch to obviate the need). You generally do not want to check the type because it indicates a flaw in the design, however. Why do you want to do this?   ;Quote:Original post by RogerThat123yeah but in your code for the function, how can you tell what type the parameter is if its just type template.I want to know if i can tell the type being passed into it, inside the function.You venture into the twisted land of compile-time programming. Do you know about template specialization? You can use it to form the equivalent of a compile-time if statement by specializing function templates for specific parameters. The individual specializations act as ifs, since they are only called if the type matches the specialization, and the non-specialized template acts as the else. Something like this:template <class T> void Func(T val) { /* Do some stuff */ }template <> void Func<int>(int val) { /* Do int specific stuff */ };  what you are looking for is called reflection. sadly standard c++ has no refelction. luckily specific c++ implementations such as visual c++ contain reflection. i think the keyword there is similar to the 'instanceof' keyword in java.   ;Quote:Original post by jpetrietypeid, dynamic_cast, specialization, or via polymorphism (or using polymorphic behavior and dynamic dispatch to obviate the need). You generally do not want to check the type because it indicates a flaw in the design, however. Why do you want to do this?Because in my create function, I want another object with an empty pointer, example in a foreign objectclass dog{A* a2;};now inside my create function I want to point a2 to my newly create object. ;  This implies that you do not want one function for this any longer. It is exactly counter to your original goal of collapsing four functions that do the same thing for different types into one function; now you want three functions that do one thing, and one that does something slightly different.Also, your subsequent explanation is still not really sufficient enough to illustrate what you want to do, since you cannot assign that a2 member to anything without an instance of the containing dog class, which you'd need to pass to the function in question. So again, what are you trying to do? The more detail you provide, the more useful the responses to your query will be.   