templates specialisation

altafahmed2k4's Avatar, Join Date: Aug 2006
Go4Expert Member
hi
i m using borlands turbo c++ ide compiler dos based

i entered thw following code
Code:
// template specialization
#include <iostream>
using namespace std;

template <class T>
class container {
    T element;
  public:
    container (T arg) {element=arg;}
    T increase () {return ++element;}
};

template <>Encountered error "invalid argument list" 
class container <char> {
    char element;
  public:
    container (T arg) {element=arg;}
    char uppercase ();
};

template <>Encountered error "invalid argument list" 
char container<char>::uppercase()
{
  if ((element>='a')&&(element<='z'))
  element+='A'-'a';
  return element;
}

int main () {
  container<int> myint (7);
  container<char> mychar ('j');
  cout << myint.increase() << endl;
  cout << mychar.uppercase() << endl;
  return 0;
}
also i am not able to use namespace std;
may i know what is the reason
altafahmed2k4@yahoo.co.in

Last edited by shabbir; 18Oct2006 at 10:04.. Reason: Code formating.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Your code is absolutely fine as far as compilation should go but its just Turbo C3 does not support it in a manner you have written it. I think you should be doing something like template <char>.

Regarding namespace turboC3 does not support namespaces and its done in MS compilers
0
altafahmed2k4's Avatar, Join Date: Aug 2006
Go4Expert Member
Then is it like that

template specialisation is not possible in Borlands Turbo C++ version 3.0

if yes please direct me.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Probably you cannot but I would suggest you not using the TC3 unless and until you are bound to be using that as lots of things dont work correctly in TC3
0
altafahmed2k4's Avatar, Join Date: Aug 2006
Go4Expert Member
Thank u shabbir i tried using bloodshed compiler

the code is not working there too

can you direct me to how i can master this compiler

any specific site
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Mastering the compiler is not what will help you. Try using the latest compilers from GCC(on Linux Systems) or MS (on Windows)