Author Topic: STL errors only in specific files  (Read 3593 times)

jhessin

  • Guest
STL errors only in specific files
« on: August 12, 2009, 08:20:04 pm »
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;
}

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

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 ===|

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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: STL errors only in specific files
« Reply #1 on: August 12, 2009, 08:27:08 pm »
support for STL only goes as far as the main.cpp file.
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ