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

C++ string in class

Name: Anonymous 2007-09-10 20:06 ID:aWmcM4MD


class Myclass {
    public:
        Myclass (char*);
        ~Myclass ();
        char* Myclass ::getName();
    protected:
        char* name;
};

Myclass ::Myclass (char* inname){
    name = new char[strlen(inname)*sizeof(char)];
    strcpy(name, inname);
}

char* Tile::getName(){
    return name;
}


How come name returns a random pointer? I'm declaring everything right, but for some reason it gets corrupted...

Name: Anonymous 2007-09-11 0:10 ID:lU4F1D0n


#include <string>

class Myclass {
    public:
        Myclass (string s) {name = s;};
        ~Myclass ();
        string Myclass ::getName(return name;);
    protected:
        string name;
};


error C2146: syntax error : missing ';' before identifier 'name'

LOL WUT?

how do i put a string in a class?

this is bs. C has so many understandable ways of doing things :/

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