Guest User

Untitled

a guest
Feb 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. CPoly &
  3. CPoly::operator=(const CPoly &rhs)
  4. {
  5.  
  6. if (this == &rhs)
  7. { // if self assignment
  8. return (*this); // just return without any modifications to the input object
  9. }
  10.  
  11. else
  12. {
  13.  
  14. m_nOrder = rhs.m_nOrder;
  15.  
  16. if (m_pCoeffs != NULL)
  17. {
  18. delete [] m_pCoeffs;
  19. m_pCoeffs = NULL;
  20. }
  21.  
  22. m_pCoeffs = new CCmplxNum[m_nOrder + 1];
  23.  
  24.  
  25. if (rhs.m_szVarName != NULL)
  26. {
  27. delete [] m_szVarName;
  28. m_szVarName = NULL;
  29. }
  30.  
  31. m_szVarName = new char[strlen(rhs.m_szVarName)+1];
  32.  
  33. if ((m_nOrder != -1) && (m_pCoeffs != NULL) && (m_szVarName != NULL))
  34. {
  35.  
  36. for (int i = 0; i < (m_nOrder + 1); i++)
  37. {
  38. m_pCoeffs[i] = rhs.m_pCoeffs[i];
  39.  
  40. for (int i = 0; i < strlen(rhs.m_szVarName)+1; i++)
  41. {
  42. //strncpy(m_szVarName, rhs.m_szVarName, 10);
  43. m_szVarName[i] = rhs.m_szVarName[i];
  44. }
  45. }
  46. }
  47. else
  48. {
  49. cerr << "polynomial nt created" << endl;
  50. m_nOrder = -1;
  51. m_pCoeffs = NULL;
  52. m_szVarName = NULL;
  53. }
  54. return *this;
  55. }
  56. }
Add Comment
Please, Sign In to add comment