GDICommander 54 Posting Whiz in Training

The C++ syntax for memory allocation for array does not allow any shortcut like what's done in Java.

You can always simulate the Javs syntax by creating a function that takes a variable number of arguments and returns an allocated int array with all the values received at their correct position in the array.

I disagree with that approach, because evaluation of functions with variable arguments have the reputation to be slow.

GDICommander 54 Posting Whiz in Training

Maybe the listProb lists have already an empty list inside after entering the loop. You can print their content before entering the loop.

I guess that normDistProb returns an empty list somehow.

GDICommander 54 Posting Whiz in Training

Ok... what's wrong with the actual code?

GDICommander 54 Posting Whiz in Training

Maybe you're comparing a GameObject with a Player, but I don't think so...

Have you deferenced BOTH pointers? (current AND insertedPlayer)

Note that you put overrided operators PRIVATE, so this is hidden... Try to put them PUBLIC.

GDICommander 54 Posting Whiz in Training

Can you show your implementation of the overloaded operators you mentioned?

GDICommander 54 Posting Whiz in Training

Have you tested all your functions with unit tests? (You can easily write unit tests in Python, see http://docs.python.org/library/unittest.html)

If you haven't tested what you wrote, then you may find a lot of bugs inside your code when you'll be using it for real.

GDICommander 54 Posting Whiz in Training

I would add what is necessary to add... Who will be using your code?

GDICommander 54 Posting Whiz in Training

You are copying the content of the cin stream, so it will never end until you press Enter, maybe. So it never ends.

GDICommander 54 Posting Whiz in Training
GDICommander 54 Posting Whiz in Training

If you are using UNIX, you can use valgrind to check for memory leaks. You need to add --tool=memcheck on the command line to check for leaks.

GDICommander 54 Posting Whiz in Training

Looks good, but there is a piece of code I would like to show you:

if(is_door_opened==true)

You can simplify this conditionnal expression with:

if (IsDoorOpened())

and make this method private, if no other entity external to the class has a need for it. This is a refactoring tip (Simplify Conditional Expressions) and not a object-oriented tip. When you have a lot of AND and OR in a condition, better use a method like the one presented to make the code more readable.

GDICommander 54 Posting Whiz in Training

I did a mistake in my last post: the >> operator reads data until a end-of-line character OR a whitespace is found.

GDICommander 54 Posting Whiz in Training

Are you sure that the file denoted with the name you provided exists?

I'm pretty sure that the answer is yes, but do you really have gSize vertices in your file? Do you really have a line at each end of a vertex definition in your file that is -999? Do you have a operator!= that takes a int has a parameter?

Remember that the >> operator reads data until a end-of-line character is found (this operator reads a line in a file).

If it's possible, can you post the content of the input file?

GDICommander 54 Posting Whiz in Training

You can do this:

no warnings ;
no warnings 'all' ;

GDICommander 54 Posting Whiz in Training

Have you created a new project or have you just opened the file? Opening the file only prevents you from building the executable. You must create a project.

GDICommander 54 Posting Whiz in Training

See this address for the express edition, I recommend it instead of VC++ 6.0:

http://www.microsoft.com/Express/

GDICommander 54 Posting Whiz in Training

Maybe you have a specific setting, a flag or something. Check this page:

http://social.microsoft.com/Forums/en-US/vcgeneral/thread/d2677732-d756-42e5-b2f1-5b040819c037

Don't forget that a re-install may solve the problem.

GDICommander 54 Posting Whiz in Training

Do you have a 64-bit machine?

Have you tried to restart Visual Studio and build again your solution?

Also, I know that a "Clean Solution / Rebuild Solution" solves a lot of problems.

You can click on the error message and press F1. If you're lucky, that will lead you to more info on the error. And also, Google is your friend!

GDICommander 54 Posting Whiz in Training

Don't forget to make the thread as solved.

GDICommander 54 Posting Whiz in Training

According to cplusplus.com (http://www.cplusplus.com/reference/string/string/append.html) ...

string& append ( size_t n, char c );
Appends a string formed by the repetition n times of character c.

Here, a string is formed to make the request to the map. This is how I do it. There are other ways to do it, like using iterators. You can see it on the URL I put above.

GDICommander 54 Posting Whiz in Training

About my last post, I have realized that operator[] returns a const char& and not a const char* that will have be used to construct a string.

Instead of using peek, you can use conditions, like this (it works):

map<string,string>datamap;

	  datamap["A#"]="b";
	  datamap["C"]="DD";

	  string change = "CCA#A#C";

	  //getline(cin,change);

	  for(size_t i=0; i<change.size(); i++)
	  {
		  if (i != change.size() && change[i+1] == '#')
		  {
			  string toAsk;
			  toAsk.append(1, change[i]);
			  toAsk.append(1, change[i+1]);
			  cout << datamap[toAsk];
			  ++i;					//We will be after the #...
			  continue;
		  }

		  //output based on what character gets passed to the map
		  cout << datamap[string(change.begin() +i,change.begin() +i+1)];
	  }

I hope that it helps...

For more info about peek (for your information), look at this page:

http://www.cplusplus.com/reference/iostream/istream/peek.html

GDICommander 54 Posting Whiz in Training

Ok, first, it is very ugly to do:

string(change.begin() +i,change.begin() +i+1)

Instead, do this:

change[i]

It will return the ith character of the string.

GDICommander 54 Posting Whiz in Training

You can still use a refactoring tip: Introduce Explaining Variable.

Declare, for each equals(), a bool that contains the result of this operation and use them in the if statement instead of the ugly list of equals() calls.

GDICommander 54 Posting Whiz in Training

First, you should access the static methods (add, minus) in a static way, like Money.add( ... ) and Money.minus ( ... ).

Accessing a static method on an object (ok) is not supposed to change the object, because it is a static method, you don't have to instantiate a class to call it.

What you return is not taken by ok to create an object. You should do:

ok = Money.add(good, bad);

And it should work.

GDICommander 54 Posting Whiz in Training

Use System.out.println("Your message") to print debugging messages about your input string and the value of every variable. First, ensure that the string is received from the scanner. After, look in the code of the stack.

GDICommander 54 Posting Whiz in Training

You should put the numbers at some place... and check every one of them...

That is an extremely easy solution.

GDICommander 54 Posting Whiz in Training

On which OS are you using?. It may not do a difference, but the "slash-backslash" complexity can cause this.

Otherwise, look at the renameTo method. Look for special permissions or existence of the source file.

GDICommander 54 Posting Whiz in Training

This amount of code is impossible to read!

Test your stack before attempting to use it!

GDICommander 54 Posting Whiz in Training

If the file you want to copy is already used by an another process (if this is it), you cannot have access to it (except if you have special permissions).

This is very useful program for spotting file handles for every process: Process Explorer. Google it if you have a chance.

GDICommander 54 Posting Whiz in Training

This is what I suggest to you:

1) You will take your FileToArray() function and you will test it with all the possible limit cases (even if they are stupid). If there's no problem, then you will remove it from the post.

2) Do you know JUnit? I strongly suggest you to use it. It is a software testing environment. You will write your tests and use the limit cases for testing. Then, you will see your bug.

This is a common practice in software development to test EVERYTHING before doing something else. And yes, you can do it everytime.

GDICommander 54 Posting Whiz in Training

Creating a recursive function that returns the factorial will solve this problem.

if 0, then return 1
if 1, then return 1
else do n * fact (n - 1)

This is not a tail-recursive version (sorry for the programmming purists), but it will do for your needs.

GDICommander 54 Posting Whiz in Training

What I call a function is something that is not inside a int main(). If you do it with a int factorial() function, you will be able to use it more easily in an another program than a int main().

Putting all the treatment in a function will eliminate the problem of the same factorial for every run.

If you really want to not use function, just set fact to 1 after the computation, but I strongly suggest the use of a factorial() function.

GDICommander 54 Posting Whiz in Training

I will suggest you this:

Write a function that takes an integer and returns its factorial. (Use the power of recursion)

Test it (IMPORTANT!) and after, call it in your program. That will simply your code.

GDICommander 54 Posting Whiz in Training

So, it is a math problem. Go there:

http://en.wikipedia.org/wiki/Poisson_distribution

GDICommander 54 Posting Whiz in Training

First, indent your code. It is more readable in that way.

Second, how will you find the answer with a pencil and a paper? Answering this question will lead to the structure of your program. Understand the equation first and compute it after!

Don't hesitate to use functions to wrap complicated computations. And be careful with arithmetic operations with different types.

GDICommander 54 Posting Whiz in Training

This is not a C++ question. Just think about how you will represent it and if you have problems with C++, your post will be more likely to be solved.

For the update, do a search on the Observer design pattern. That will be a good start.

GDICommander 54 Posting Whiz in Training

Check if you are accessing memory that you have not allocated. Are you using an invalid pointer? Are you using pointers?

Are you referencing an iterator on the end of a vector? (ex: it.end())

Without source code, I cannot give you more advice. I hope that this tips will help.

GDICommander 54 Posting Whiz in Training

You can use gdb to debug your program. The following link can help:

http://www.cygwin.com/cygwin-ug-net/gdb.html

GDICommander 54 Posting Whiz in Training

You need to put "new Venn()" in your constructor or after the declaration of forstevenn, and make sure that the String object to print is initialized (via new).

GDICommander 54 Posting Whiz in Training

By the way, try indenting your code like this:

int main()
{
}

or

int main(){
}

It is more easily readable.

GDICommander 54 Posting Whiz in Training

I don't see brackets surronding the parralelIterative function. If this explains the error, it will be good. Also, a semi-colon after the parralelIterative line is not correct.

GDICommander 54 Posting Whiz in Training

Two possibilities here:
-the String of Venn is null.
-p is null and that is why the message is not printed.

Use System.out.println("Debug messages") to trace the execution of the code. This will help.