Jump to content

  • Log In with Google      Sign In   
  • Create Account


Washu

Member Since 24 Mar 2001
Offline Last Active Yesterday, 09:49 PM
*****

Posts I've Made

In Topic: looping through struct array

20 July 2014 - 05:31 PM

There's a few different ways to do this, you can use a vector of strings (or deque), if you're using C++11 then you can use the ranged base for, but if you want the items numbered then standard for loop probably works best... sample below...

#include <iostream>
#include <string>
#include <vector>

struct character
{
	unsigned int health;
	std::vector<std::string> inventory;
};

void displayinventory()
{
	character player = { 100, { "Gun", "Knife", "Blade" } };
	for (size_t i = 0; i < player.inventory.size(); ++i)
	{
		std::cout << i << ". " << player.inventory[i] << std::endl;
	}
}

int main() {
	displayinventory();
}

In Topic: Inter-thread communication

20 July 2014 - 05:12 PM

 

 Additionally boost has some lock free containers in it, and if I recall correctly intel released a whole library of lock free data structures.

Cool, last time I looked at that, it was just the idea / submission-for-review stage, not actually accepted into boost yet.

 

Yeah, its nice that they finally got it up and going... as for the Intel library I was thinking of.... here's a link


In Topic: C++ avoiding pointers

16 July 2014 - 05:26 PM

There is nothing wrong with using dynamic memory. In fact, for any suitably non-trivial application you will find it impossible to NOT have dynamic memory allocation.

 

If you're doing this in C++ then you should be using modern C++ methodologies, such as smart pointers.

 

Additionally, when implementing your own classes that contain raw pointers you should always be sure to implement the rule of three at the minimum, rule of five at best.


In Topic: Inter-thread communication

16 July 2014 - 05:17 PM


If this is for Windows only, there's a lock-free singly linked list somewhere in the Win32 API (I forget the name... Slist?), which is probably used by their own messaging stuff.

Yes, SList is correct.

 

Additionally boost has some lock free containers in it, and if I recall correctly intel released a whole library of lock free data structures.


In Topic: Is c++ good

16 July 2014 - 12:43 PM


Regarding interview tests, I've usually seen C used for that (even for Lua jobs) to see if someone understands their fundamentals well.

 

Honestly, when asking interview questions I usually don't care what language the person uses to solve the problems posed, just as long as they can solve them. There are some occasions where we'll specify what language should be used to solve a particular problem, but that's actually pretty infrequent. I can understand it being more common in game development though.


PARTNERS