D
D
Danil Vaskevich2021-06-01 14:31:57
JavaScript
Danil Vaskevich, 2021-06-01 14:31:57

How to fix an error in the = operator?

You need to write an assignment operator for the class. Everything is already written, as it were, but an error unknown to me spoils all the raspberries. Here is the function code:

void String::operator=(String& other) {
  delete[]this->string_;
  this->string_ = new char[strlen(other.string_)];

  for (size_t i = 0; i < strlen(other.string_); i++)
  {
    this->string_[i] = other.string_[i];
  }
}

Here is the main code:
#include "String.h"
#include <iostream>
using namespace std;

int main() {
  
  String str1;	
  str1.inputString();

  String str2;
  str2 = str1;
  
  str2.print();
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2019-02-02
@gfr3

First, you need to move the resize processing out of the tab event - you put another handler on each switch.
Then, wrapping in is also not necessary. This is onLoad, all this code should be wrapped in it. This will give you 80% results for 1% effort:$('.item').matchHeight()$(function() {})

function resize() {
  if ( $(window).width() < 992 ) {
    $('.item').matchHeight();
  }
}

$(window).resize(resize);

resize();

The remaining 20% ​​you can get using throttle / debounce .

W
Wataru, 2021-06-01
@DaniVffgf

It is necessary to allocate +1 character memory for the trailing '\0' (which you must also put at the end).
Then, you can use strcpy instead of a manual loop. And then, your class loses a lot to std::string - consider using it. Well, or use it inside your class instead of manually allocating memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question