Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ strings

Name: Anonymous 2007-03-21 6:35 ID:QUPvos6j

I'm not sure about how allocation and cleanup works with c++ strings. Does this leak memory?


string get_filename(char * path)
{
    string file_name = path;
    int pos = file_name.find_last_of('\\');
    if (pos!=string::npos)
    {
        file_name = file_name.substr(pos+1); // what happens to the memory here?
    }
    return file_name;
}

Name: Anonymous 2007-03-21 13:40 ID:JA+l0YHH

>>4

#include <iostream>

using namespace std;

class X {
public:
    X(int) { cout << "constructor called\n"; }
    X& operator=(const X&) { cout << "assignment operator called\n"; return *this; }
};

int main() {
    cout << "X a(3)\n";
    X a(3);
    cout << "X b = 4\n";
    X b = 4;
}

When you'll run it, you'll shit bricks.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List