Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Femtosecond
Aug 2, 2003

I have a bit of code that I'm working on, and it has a use of '&' that I've never seen before.

quote:

switch(rand()&3)

I've seen rand() % 3 used a million times before, but never the &. It's still giving me random numbers but it seems like it's doing something a bit different. What does this do?

Adbot
ADBOT LOVES YOU

Femtosecond
Aug 2, 2003

Argh. I'm wanting to write a bit of code to keep track of statistics about my memory pool. I want to set up this UpdateMemoryStats function as a global so I can call it anywhere (or in the main loop) and I only want one set of stats, so I figure I should make the stats static. Unfortunately I keep getting a drat unresolved external symbol error. I'm obviously missing something... I've gone over this a bunch and I think I just need someone else to look at this or something.

Or if there's a better way to do this just suggest that.

code:
MemoryPool.hpp
==============
struct MemoryPoolStats
{
	int total_allocs;
};

class MemoryPool
{
	static MemoryPoolStats	mMemoryStats;
};

void	UpdateMemoryStats(); 

-------------------------------------------
MemoryPool.cpp
==============

void UpdateMemoryStats()
{
//an example of some operation on the mMemoryStats
MemoryPool::mMemoryStats.total_allocs = 0; //<-- I guess this is bad somehow

}

Femtosecond
Aug 2, 2003

In a C# application I'm wanting to make a class that has a List as a member, but I keep running into the issue that if I try to add some items to the List, but I run into the issue that the list is null. I thought that maybe I had to instantiate the list in the constructer of the class, but that didn't work either. I'm missing something obviously.

code:
public class Stuff
	{
	List<Banana> m_Stufflist;
		String		m_name;

		public Spreadsheet(String name)
		{
			m_name					= name;	
		}
so if I wanted to do something like
code:
m_Stufflist.Add(banana1); 
I run into an issue because m_Stufflist is null.

Femtosecond
Aug 2, 2003

DLCinferno posted:

But you're not instantiating it. You need to do either
code:
List<Banana> m_Stufflist = new List<Banana>(); 
...when you declare it, or you need to do:
code:
m_Stufflist = new List<Banana>(); 
...in the constructor.

Don't forget you still need the parens when you instantiate it. With generics it's a little confusing to have both the <> and ().

Ahh I knew I needed to create the list in some way. I actually had written in
code:
List<Banana> m_Stufflist = new List<Banana>(); 


in the constructor and that didn't work. Changing it to:
code:
m_Stufflist = new List<Banana>(); 

worked since I had already declared m_Stufflist earlier.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply