ایجاد یک فایل header دارای class
سلام!! خسته نباشید!!
بنده میخوام کلاسی که توی برنامه استفاده کردم رو داخل یک فایل header.h بریزم و پیاده سازی شو داخل فایل main.cpp انجام بدم. خب مشکل اینجاست که فایل هدر چنتا ارور میده که متوجه نمیشم چه باید بکنم..
لطفا کمک کنید.
فایل main.cpp
#include <iostream> #include <windows.h> #include <conio.h> #include <stddef.h> #include <header.h> using namespace std; int main (){ chart ch; int x; cout << "enter how many chart?"; cin >> x; ch.build(x); cout << "which?"; cin >> x; ch.change(x); ch.show(); }
اینم فایل header.h:
class chart{ private: struct con; typedef con *ptr; struct con{ string str; ptr innerptr; }; ptr head; ptr corptr; ptr newptr; public: void build(int x){ head= new con; corptr= head; corptr -> str ="null"; for (int i=0; x-1>i; i++){ newptr= new con; corptr -> innerptr= newptr; corptr= newptr; corptr -> str= "null"; } corptr -> innerptr= NULL; } void change(int x){ corptr= head; for (int i=0; x-1>i; i++){ corptr= corptr -> innerptr; } cin >> corptr -> str; } void show (){ corptr= head; while (corptr != NULL){ cout << corptr -> str << endl; corptr= corptr -> innerptr; } } };
اگه هر دو تا توی یک فایل باشن مشکلی نداره، ولی بعد از جداسازی فایل هدر چنتا اررور میده!!