title: Addition on user-defined types C++
body: <p>I am writing my own class(called "Longer") such that it can hold a number without any upper bound unlike int. I am using std::string for this. 
  I am having problem on performing addition. </p>
  
  <ol>
  <li>If i simply add two string, i can't get correct result. </li>
  <li>I thought of converting string to int and then performing addition,
  but long string can't be converted to int.</li>
  </ol>
  
  <p>How can i define my own way of adding two strings so that i get the desired result? Here is the code:</p>
  
  <p>Longer.h</p>
  
  <pre><code>#pragma once
  #include &lt;string&gt;
  
  class Longer
  {
  public:
     Longer(std::string number);
     Longer add(Longer num2);
     void print();
  private:
     std::string number;
  };
  </code></pre>
  
  <p>Longer.cpp</p>
  
  <pre><code>#include "Longer.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  Longer::Longer(std::string num): number(num)
  {
  }
  
  Longer Longer::add(Longer num2){
    return Longer(number+num2.number);
  }
  
  void Longer::print(){
  std::cout&lt;&lt;number&lt;&lt;"\n";
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Longer.h"
  
  int main(){
  
  Longer num1("123456789101112");
  Longer num2("121110987654321");
  
  
  Longer num3 = num1.add(num2);
  num3.print();
  
  }
  </code></pre>