User forums > Using Code::Blocks
STL errors only in specific files
(1/1)
jhessin:
I have discovered something very interesting when it comes to STL in CodeBlocks for windows.
I compiled the following Hello World program and it runs just fine - code completion even worked for the vector that I used:
--- Code: ---
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<string> test;
string myString = "Hello world in a vector!";
test.push_back(myString);
cout << test.at(0) << endl;
return 0;
}
--- End code ---
But when I tried to do something similar in another source file i.e. for a class:
--- Code: ---
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <vector>
class testClass
{
vector<int> master_list;
public:
testClass();
protected:
private:
};
#endif // TESTCLASS_H
--- End code ---
I get the following Error:
--- Code: ---
||=== Hello World++, Debug ===|
C:\Users\jhessin\Downloads\PortableApps\Projects\Hello World++\testclass.h|8|error: ISO C++ forbids declaration of `vector' with no type|
C:\Users\jhessin\Downloads\PortableApps\Projects\Hello World++\testclass.h|8|error: expected `;' before '<' token|
||=== Build finished: 2 errors, 0 warnings ===|
--- End code ---
I have tried putting in #include <iostream>, but that does nothing. I don't know why but it seems that support for STL only goes as far as the main.cpp file.
MortenMacFly:
--- Quote from: jhessin on August 12, 2009, 08:20:04 pm ---support for STL only goes as far as the main.cpp file.
--- End quote ---
No. Just put std:: in front of vector<int> in the second source file. Notice the "using namespace std;" does that in the first source file.
However - this is neither related to Code::Blocks nor to code completion. So I am locking this topic now as it violates our forum rules. This is not a general programming board.
Navigation
[0] Message Index
Go to full version