我有這樣的結構:在C++中,將char數組傳遞給超級錯誤?
class Base
{
public:
void doACopy(char* strToCopy) {
strcpy(str, strToCopy);
}
private:
char str[4];
};
class Derived : public Base
{
public:
void doSomething() {
char toCopy[4];
toCopy[0] = 'a'; toCopy[1] = 'b'; toCopy[2] = 'c';
Base::doACopy(toCopy); // is there any problem passing toCopy here?
}
};
我知道toCopy是在堆棧中分配。在將這個數組傳遞給super時有任何問題,在這種情況下是Derived :: doACopy?
你可能更容易使用'std :: string'。 – GManNickG 2010-09-15 04:30:21