Search found 20 matches

by fantastico
Fri Jul 24, 2009 4:16 pm
Forum: Programming Discussion
Topic: Creating a stack template
Replies: 3
Views: 389

Re: Creating a stack template

You have to think about how you will use the stack and then choose the implementation to squeeze out the last bit of performance if you really need that, in terms of asymptotic complexity a vector and a doubly-linked list are equal. However, a list will only hold the objects that are actually on the...
by fantastico
Tue Jul 14, 2009 4:03 pm
Forum: Programming Discussion
Topic: Making a template - Symbol(s) not found
Replies: 4
Views: 541

Re: Making a template - Symbol(s) not found

Pretty much the same as you would normally do except for that one include and leaving out the cpp file in the compilation process. Array.h includes Array.cpp at the end of the file, just before the #endif of the guards. You can leave the #include "Array.h" in the Array.cpp file, if your ID...
by fantastico
Tue Jul 14, 2009 1:46 pm
Forum: Programming Discussion
Topic: Making a template - Symbol(s) not found
Replies: 4
Views: 541

Re: Making a template - Symbol(s) not found

The problem is that the compiler needs to see the actual code of your functions when it instantiates a template, since it has to produce code for that concrete type and can no longer stay on a generic/templated level. Instantiation happens when the compiler sees that you wrote saArray<unsigned short...
by fantastico
Sun May 17, 2009 3:41 pm
Forum: Programming Discussion
Topic: Post Your C++ Templates.
Replies: 8
Views: 1015

Re: Post Your C++ Templates.

generic insertion sort I used in a situation where I knew an array was partly sorted already, cmpFnc has to be a class/struct with an operator() that realizes a "strictly less than" comparison template <class T, class ComparisonFunctor> void insertion_sort(std::vector<T>& arr, Comparis...
by fantastico
Sun May 03, 2009 6:00 am
Forum: Programming Discussion
Topic: [solved] getting the directory of my executable on win XP
Replies: 7
Views: 891

Re: [solved] getting the directory of my executable on win XP

Uhm, looks pretty complicated. First thing I noticed in your initial post is that "\\content\\images\\background.bmp" is not a relative path, at least it wouldn't be in linux and I'm pretty sure it neither is in windows. If you want a relative path leave out the leading backslashes or writ...
by fantastico
Sun Apr 26, 2009 3:37 am
Forum: Programming Discussion
Topic: How do I make maps scroll
Replies: 10
Views: 1213

Re: How do I make maps scroll

The player drawing is fine. The tile drawing is probably not doing what you want it to, I think. You are doing rect.x =c - myCam.getX() but c is just the number of the tile (0, 1, 2, etc) but it should be scaled by the tile width: rect.x = c * tW - myCam.getX(). The same goes for rect.y. Right now t...
by fantastico
Sat Apr 25, 2009 3:57 pm
Forum: Programming Discussion
Topic: How do I make maps scroll
Replies: 10
Views: 1213

Re: How do I make maps scroll

You should have "world" coordinates and "view" coordinates. All the game objects positions are in world coordinates and only those are used in the game logic including collision detection. Drawing is seperate and you just translate world coordinates to view coordinates (using the...
by fantastico
Sun Apr 19, 2009 5:53 am
Forum: Programming Discussion
Topic: A Bit of a Challenge: Feeling Clever?
Replies: 8
Views: 776

Re: A Bit of a Challenge: Feeling Clever?

Are you sure that function is even invertible? If the output of 2 different (or more) inputs it the same, how can you know which one was the correct one after decrypting? That's the point of most cryptographic hash functions anyway.
by fantastico
Thu Apr 16, 2009 8:43 am
Forum: Programming Discussion
Topic: OOP Help
Replies: 20
Views: 2269

Re: OOP Help

Back to vtables, does the vtable lookup involve iterating through the table? If so then it's O(n). The wikipedia article says no. Since the compiler knows about all virtual functions at compile time it can also come up with a static "name to table-index" mapping that won't change at runti...
by fantastico
Thu Apr 16, 2009 7:57 am
Forum: Programming Discussion
Topic: OOP Help
Replies: 20
Views: 2269

Re: OOP Help

It's just some notation to describe (algorithmic) complexity. O(n) means an algorithm that has some sort of input of size n runs in linear time (e.g. finding the maximum in an array of n ints). O(1) means constant time, so regardless the input size it takes a constant amount of time/steps to run. wi...
by fantastico
Thu Apr 16, 2009 4:35 am
Forum: Programming Discussion
Topic: OOP Help
Replies: 20
Views: 2269

Re: OOP Help

Arce wrote:Though not by much? Probably O(1), O(n) if it's really gay. If anybody has time to google it lemme know. ;p
I'm pretty sure it's O(1) in the sense that for any class hierarchy it takes only 1 table lookup at runtime to find the function to be executed.
by fantastico
Sun Apr 05, 2009 3:26 am
Forum: Programming Discussion
Topic: Damn I/O!! ( HELP PLEASE! )
Replies: 17
Views: 2619

Re: Damn I/O!! ( HELP PLEASE! )

Yea it should work like this: ifstream is; is.open("filename", ios::binary); is.seekg(0, ios::end); unsigned int length = is.tellg(); is.seekg(0, ios::beg); char* buffer = new char[length]; is.read(buffer, length); It should load the whole file into that byte array buffer and I guess it wi...
by fantastico
Sat Apr 04, 2009 3:14 pm
Forum: Programming Discussion
Topic: Damn I/O!! ( HELP PLEASE! )
Replies: 17
Views: 2619

Re: Damn I/O!! ( HELP PLEASE! )

thank you for all of your help! everybody!! now, fantastico, about the filen.size() is there a way to do that so that i actually get the stream size instead of name of file? Taken from http://www.cplusplus.com/reference/iostream/istream/tellg.html : is.seekg (0, ios::end); int length = is.tellg(); ...
by fantastico
Sat Apr 04, 2009 10:17 am
Forum: Programming Discussion
Topic: Damn I/O!! ( HELP PLEASE! )
Replies: 17
Views: 2619

Re: Damn I/O!! ( HELP PLEASE! )

Ginto8 wrote:or you could do filei.read((char*)&loader, ... ) ;)
The compiler would accept it, the OS and the programmer wouldn't like the result though :)
by fantastico
Sat Apr 04, 2009 4:59 am
Forum: Programming Discussion
Topic: Damn I/O!! ( HELP PLEASE! )
Replies: 17
Views: 2619

Re: Damn I/O!! ( HELP PLEASE! )

well i put the '&' before "loader" now and i get this (line 18) error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::read(std::string*, size_t)'| That's because you are passing the function a pointer to a std::string while it's expecting a point...