注意:我已经彻底搜索过SO,并且发布了针对其他类似问题的解决方案在这里并不适合我。C++错误:重新定义类
我写在C++我自己定制的“弦”类,和我encoutering以下错误编译时:
./PyString.h:8:11: error: out-of-line declaration of 'PyString' does not match any declaration in 'PyString' PyString::PyString (char*); ^
./PyString.h:9:11: error: definition of implicitly declared destructor PyString::~PyString (void);
pystring.cpp:4:7: error: redefinition of 'PyString' class PyString {
对于第一和第二的错误,周围的析构函数移动到类在cpp
文件中定义本身不起作用。
至于第三个错误,我似乎无法解决它 - 我不重新定义类!
这里是pystring.h
:
#ifndef PYSTRING_INCLUDED
#define PYSTRING_INCLUDED
class PyString {
char* string;
};
PyString::PyString (char*);
PyString::~PyString (void);
#endif
这里是:
#include "PyString.h"
#define NULL 0
class PyString {
char* string = NULL;
public:
PyString(char inString) {
string = new char[inString];
};
~PyString(void) {
delete string;
};
};
任何帮助不胜感激。
,我认为你应该得到[一好的初学者书](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)并重新开始,因为它没有太多在你显示的源是正确的。 –
查找* .cpp文件中定义的头中定义的类的示例。 – juanchopanza