2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Find bug fix (C++)

Posted at

#include
using namespace std;
/*
int main(){
printf("Hello world\n");
return 0;
}
*/

//Example #3 (C++ code): What is the bug and why is it a problem?
const char* append(const char* s1, const char* s2) {
string s(s1);
s += s2;
return s.c_str();
}

void foo() {
const char* total = append("abc", "def");
}
/*
//Example #4 (C++ code): What is the bug and why is it a problem?
void erase(list &l, int v) {
list::iterator i = l.begin();
for(; i != l.end(); ++i) {
if(*i == v)
l.erase(i);
}
}

//Example #11 (C++ code): What is the bug and why is it a problem?
class Base {
public:
int x;
};

class Derived : public Base {
public:
int y;
};

void init(Base *b) {
for( int i = 0; i < 3; ++i) {
b[i].x = 0;
}
}

void foo() {
Derived arr[3];
init(arr);
}
*/

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?