I'm new to C++ and am having trouble implementing this extremely simple class in Visual C++:
The file testClass.h contains:
Code:#ifndef TESTCLASS_H #define TESTCLASS_H class testClass { public: testClass(void); ~testClass(void); vector<int> v; }; testClass::testClass(void) { } testClass::~testClass(void) { } #endif
(Vector is #included in main.) That's all very simple and it compiles properly. However if I take the constructor and destructor and move them to a .cpp file, as everyone says you're supposed to do, it breaks:
file testClass.h
with file testClass.cpp:Code:#ifndef TESTCLASS_H #define TESTCLASS_H class testClass { public: testClass(void); ~testClass(void); vector<int> v; }; #endif
After splitting the code into two files, the compiler complain about the vector<int> v; line.Code:#include "testClass.h" testClass::testClass(void) { } testClass::~testClass(void) { }
syntax error : missing ';' before '<'
missing type specifier - int assumed
unexpected tokens preceding ';'
I can't figure out what I'm doing wrong here. How do I move the class's functions into a different file?
For reference, the main program was:
Thanks in advance for any help. I've been pounding away at this for hoursCode:#include <iostream> using namespace std; #include <vector> #include "testClass.h" int main() { testClass t; return 0; }![]()



LinkBack URL
About LinkBacks




