1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

templates specialisation

Discussion in 'C' started by altafahmed2k4, Oct 18, 2006.

  1. altafahmed2k4

    altafahmed2k4 New Member

    Joined:
    Aug 26, 2006
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    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 <>[B]Encountered error "invalid argument list"[/B] 
    class container <char> {
        char element;
      public:
        container (T arg) {element=arg;}
        char uppercase ();
    };
    
    template <>[B]Encountered error "invalid argument list"[/B] 
    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 a moderator: Oct 18, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    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
     
  3. altafahmed2k4

    altafahmed2k4 New Member

    Joined:
    Aug 26, 2006
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Then is it like that

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

    if yes please direct me.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    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
     
  5. altafahmed2k4

    altafahmed2k4 New Member

    Joined:
    Aug 26, 2006
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Mastering the compiler is not what will help you. Try using the latest compilers from GCC(on Linux Systems) or MS (on Windows)
     

Share This Page