5 Forum Posts by "Megas-XLR"
In my opinion two things are wrong.
1) You've declared the displayContents function as taking a parameter of type int but then you supply an array of int when calling the function. In C/C++ you can't pass arrays directly as parameters. Instead you need to pass a pointer to the array.
2) Since you've declared the main function to return an int. You should return an int from the main function.
#include <iostream>
using namespace std;
void displayContents(const int *numbers);
int main()
{
int numbers[5] = {0, 1, 2, 3, 4};
displayContents(numbers);
return 0;
}
void displayContents(const int *numbers)
{
for (int i = 0; i < 5; i++)
{
cout << "numbers[" << i << "] = " << numbers[i] << endl;
}
}
Sounds like you may not have added the jar file to the project classpath. See if the
Netbeans docs are any help.
At 5/13/06 02:12 PM, CronoMan wrote:
So you mean that byte code is compiled to native code?
It's not. That would mean that large applications such as Azureus etc would have about 5-10 minutes of initialization time, since it needs to be translated to native in order to run.
Java uses a Just In Time (JIT) compiler to translate bytecode to native code. This means it doesn't need to compile the whole program at startup, just the bits it actually needs at any one point in time. Second, translating from bytecode to native is a lot quicker than source code to native since a load of the work is already done.
And why would you compile to bytecode in the first place if you can just compile it to native in the beginning?
It would not be cross platform then.
So why aren't game developers using Java to make games, or at least use it as a scripting language? Why would Epic Games spend time and money developing UnrealScript if they could just use Java instead?
Unless I've entered a parallel world this morning, the vast majority of games on mobile phones are written in Java. While it's true java is not a commonly used in desktop games it's not true to say it's never used . Check out jake a quake 2 engine written in java
http://www.bytonic.d../jake2_webstart.html
Seriously, I can't see how you can miss the logic.
I'll say it again;
JVM is made in C++, the libraries are written in C++
How can something written in a language be faster than the compiler it was compiled in?
Easy, when you compile a C/C++ program you need to compile that code to the lowest common denominator, usually of a Pentium [pro] class processor. Therefore when you run that code on a modern P4 or Opteron you're not using all the capability of that machine. On the other hand since Java compiles the byte code to native code at runtime. The JIT can generate code to use the full capability of the processor.
Assuming your talking about the windows platform, check out the very excellent Code Project site . Specifically
this article .
I think you're problem is the GetInput function don't get the caller what you expect. Since the parameter total is passed by value and not passed by reference. The caller (the main function) is not get the variable total set there.
BTW This is C++ code, not C. It will not complie is you use a standard C compiler.

