Dev-C++ and STL compile prob
Mark Oates

I'm using Dev-C++ 4.9.8.10 with gcc 3.2

I had some wierd stuff happen with the compiler and managed to get rid of most of it with
-D__GTHREAD_HIDE_WIN32API
-Wno-deprecated
(thanks to the forum search)

but I still have some problems compiling.

#include "allegro.h"

#include <vector.h>

vector<int> hey_there;

int main()
{
    hey_there.push_back();

    allegro_init();
    allegro_message("punkazz");
    
} END_OF_MAIN();

I get the errors:

 C:\Documents and Settings\Mark\Desktop\The Stuff\programming\C - C++\Trying a new project\main.cpp
[Warning] In function `int _mangled_main()':
9 C:\Documents and Settings\Mark\Desktop\The Stuff\programming\C - C++\Trying a new project\main.cpp
no matching function for call to `std::vector<int,  std::allocator<int> >::push_back()'
9 C:\Documents and Settings\Mark\Desktop\The Stuff\programming\C - C++\Trying a new project\main.cpp
no matching function for call to `std::vector<int,  std::allocator<int> >::push_back()'
9 C:\Documents and Settings\Mark\Desktop\The Stuff\programming\C - C++\Trying a new project\main.cpp
no matching function for call to `std::vector<int,  std::allocator<int> >::push_back()'

eh?

kazzmir

A)

#include <vector>

b) push_back() needs an argument, no?

hey_there.push_back(1);

23yrold3yrold

EDIT: What he said. :P

To elaborate on the first one: all standard C++ headers lack file extensions.

ReyBrujo

Don't you need to put a value into the push? A number, in example, since your vector is made of integers?

(Edited: It feels nice to be beaten along with 23 :))

Mark Oates

a -- if I do that then I get
'vector is used as a type and not defined as a type'

b -- doesn't have to..

... wait a sec..

23yrold3yrold
Quote:

a -- if I do that then I get
'vector is used as a type and not defined as a type'

a -- "using namespace std;"? ;)

Quote:

b -- doesn't have to..

b -- yes it does.

ReyBrujo

Hmm... which STL you are using? That is a strange error. And you do need an argument, at least in your version of STL.

Mark Oates

aha! it works now.

#include "allegro.h"
using namespace std;
#include <vector>

vector<int> hey_there;

int main()
{
    hey_there.push_back(1);

    allegro_init();
    allegro_message("I hate it when you're right");
    
} END_OF_MAIN();

I'll have to go back and change all the push_back()s. :( I didn't have to have a value with the last gcc 2.95.3-6. ???
why was I mislead for so long... .nooooooo :'(

:P

ReyBrujo

Do include <vector>, which is what the standard enforces. And do the using namespace std after all includes.

23yrold3yrold

Yeah, get that ".h" out of there before things get nasty in here. >:(

Mark Oates

oi, thanks alot everybody, it's working now. even though I'll have to rewrite a good portion of my game. :P

Quote:

yeah, get that ".h" out of there before things get nasty in here.

sorry that was a typo.. fixed it.

X-G

Also, for some reason I forgot exactly it's not recommended to have using namespace std; in headers. Use the explicit namespace specifier there.

23yrold3yrold

That isn't a header file. ;)

And the reason it's bad practice is that you pollute the global namespace for any file you then later include that header in. The explicit namespace specifier should be used in headers, and whatever the heck you feel like using in source files.

Thread #374989. Printed from Allegro.cc