It's been awhile since I've done C++ so I'm having a bit of trouble here. I'm getting this error on the line where I declare allQueue in the main file. I've obviously stripped out a lot of code that I don't think is required, if you need anything more let me know.
Compiling with
g++ mainFile.cpp MyClass.cpp extraObjectFile.o -o mainFile
Generates:
error: expected constructor, destructor, or type conversion before ‘<’ token
main file
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include "MyClass.h"
vector<MyClass> allQueue;
int main()
{
allQueue.push_back(new MyClass(100));
}
MyClass.cpp
#include "MyClass.h"
MyClass::MyClass(int start_priority)
{
priority = start_priority;
}
int MyClass::getPriority()
{
return priority;
}
MyClass.h
class MyClass
{
int priority;
public:
MyClass(int);
int getPriority();
};
std::beforevector, and since its not worthy of its own answer, it is because thevectortemplate belongs to thestdnamespace. An alternative would be to haveusing namespace std;after your includes. See http://www.cplusplus.com/doc/tutorial/namespaces/