我有这样的结构:在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