0

I have a function in a class which returns different type of objects ,

template <class T>
T Create(int i) {
  if(i==0) return new B();
  else return new A();
}

but this Create method must be virtual , how can I make it? I got "template may not be virtual" error. thank you Edit: I tried : template< class T > virtual T Create__Account(int i) = 0;

gsamaras
  • 71,951
  • 46
  • 188
  • 305
ccca
  • 75
  • 2
  • 11
  • 7
    See http://stackoverflow.com/questions/2354210/can-a-member-function-template-be-virtual , specifically sbi's answer. – Yam Marcovic Apr 06 '16 at 06:59
  • I read it , but I could not understand how I can make a virtual function , and override it to return different type of objects in an inherited class – ccca Apr 06 '16 at 07:22
  • 2
    the example above makes no sense. can you post code that represents your real intent? – Richard Hodges Apr 06 '16 at 07:29

0 Answers0