Home c++ How to set the synonym for the method of the method?

How to set the synonym for the method of the method?

Author

Date

Category

There is a class, a template method is defined there, how can I specify several synonyms of this method with different template parameters?

class codecontainer {
Public:
 TEMPLATE & LT; Class T & GT;
 Code * AddCode (Const Std :: String Name, Int Code);
 Code * AddCodeInteger (Const Std :: String Name, Int Code) {
  Return AddCode & LT; Int & GT; (Name, Code);
 }
 Code * AddcodeFloat (Const Std :: String Name, Int Code) {
  Return AddCode & LT; Double & GT; (Name, Code);
 }
 Code * AddCodeString (Const Std :: String Name, Int Code) {
  Return AddCode & LT; STD :: STRING & GT; (Name, Code);
 }
 Code * AddcodeBoolean (Const Std :: String Name, Int Code) {
  Return Addcode & LT; BOOL & GT; (Name, Code);
 }
};

Answer 1

The task is not entirely understood, in your code the template parameter is not used anywhere. If you mean Specialization templates, you can do this:

template & lt; TypeName T, Int Size & GT;
Void Print (StaticArray & LT; T, Size & GT; & AMP; Array)
{
  For (int count = 0; Count & lt; size; ++ Count)
  STD :: COUT & LT; & LT; Array [Count] & lt; & lt; '';
}
TEMPLATE & LT; & GT; // Specialization template
Void Print (StaticArray & Lt; Char, 14 & gt; & amp; array)
{
  For (int count = 0; Count & lt; 14; ++ Count)
  STD :: COUT & LT; & LT; Array [Count];
}
Template & lt; int Size & gt; // Partial Template Specialization
Void Print (StaticArray & Lt; Char, Size & GT; & amp; Array)
{
  For (int count = 0; Count & lt; size; ++ Count)
  STD :: COUT & LT; & LT; Array [Count];
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions