News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

STL errors only in specific files

Started by jhessin, August 12, 2009, 08:20:04 PM

Previous topic - Next topic

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:



#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:



#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:



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

MortenMacFly

Quote from: jhessin on August 12, 2009, 08:20:04 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]