C++ Stuff

BlitzMax Forums/BlitzMax Programming/C++ Stuff

Czar Flavius(Posted 2007) [#1]
I am trying to import C++ which uses vectors and the random_shuffle function but I'm getting errors about them. I've included <vector> and <algorithm>. I developed the C++ code in Visual Studio 2005 which I assume gets those things automatically, but how do I get them for C++ being imported into BlitzMax? Is it even possible to use vectors in BM? (Please say yes or I just wasted my life on hopeless game!)


FlameDuck(Posted 2007) [#2]
I developed the C++ code in Visual Studio 2005
Your mission Jim, should you chose to accept it, is to get it running under GCC first.

Is it even possible to use vectors in BM?
It depends on your interface. I'd have to say not immediately - but you can probably hack it well enough.


skidracer(Posted 2007) [#3]
I posted a tutorial using STL with blitzmax a while ago.


Czar Flavius(Posted 2007) [#4]
Ah I see I might have said something misleading. I don't mean directly use vectors in BM. Vectors are used by the C++ but not directly anything to do with BM.

Skidracer I'll check out your tutorial. Thanks.


Czar Flavius(Posted 2007) [#5]
Hello. I have looked in your tutorial but I am still stumpted. You have included <vector> but you don't even use any vectors in your code. What should I do now?

Here is the troublesome code, where uint is unsigned int:
 void placemines(uint mines)
	  {
		remaining = (x-2) * (y-2) - (minenum = mines);
		srand(time(0));
		vector<uint> placementx(x-2);
		vector<uint> placementy(y-2);
		forall(i, x-2)
		    placementx[i] = i+1;
		forall(i, y-2)
		    placementy[i] = i+1;
		random_shuffle(placementx.begin(), placementx.end());
		random_shuffle(placementy.begin(), placementy.end());
		forall(i, mines)
		    mine[placementx[i]][placementy[i]] = true;
	  }


Here are the errors I get from BM:

In member function `void
gametype::boardtype::placemines(unsigned int)':
`vector' undeclared (first use this
function)
(Each undeclared identifier is reported only
once for each function it appears in.)
parse error before `;' token
parse error before `;' token
`placementx' undeclared (first use this
function)
`placementy' undeclared (first use this
function)
`random_shuffle' undeclared (first use this
function)


Brucey(Posted 2007) [#6]
Dear oh dear...

What happens if you prefix vector with std:: ?

eg.
std::vector<uint> placementx(x-2);


?

Best place for C++ help is a good book or Google it.


skidracer(Posted 2007) [#7]
or alternatively place the following after your includes:
using namespace std;



Czar Flavius(Posted 2007) [#8]
AHA! I could kiss you!

I originally included the namespace so I could use cin/cout to test my code, but when I stripped it down for Blitzing I deleted <iostream> and (argh!) the namespace.