karse23
karse23

Reputation: 4115

Looking for equivalence to typedef and array from C to Java

Excuse me because I am a beginner in Java ...

I want to translate the following code that I have done in C to Java:

#define ROWIMAGES 5
#define COLUMNIMAGES 11

typedef struct { 
    int posX; 
    int posY; 
    int active; 
} image;

image images[COLUMNIMAGES][ROWIMAGES];

I'm trying to translate it as follows:

private static final int ROWIMAGES = 5;
private static final int COLUMNIMAGES = 11;

class image{
    int posX;
    int posY;
    int active;
}

image images[COLUMNIMAGES][ROWIMAGES];

The array in Java throws a syntax error, what's wrong?

Thanks in advance.

Upvotes: 0

Views: 272

Answers (2)

user496960
user496960

Reputation:

  1. The right syntax would be image[][] images = new image[COLUMNIMAGES][ROWIMAGES]. In Java you have to call new on an array.
  2. You have to code within a method-body.

Additional hints:

  1. Your class name should be "Image" to satisfy the Java naming conventions.
  2. Perhaps you should start with the basics. There are lots of tutorials on the web.

Upvotes: 1

Louis Wasserman
Louis Wasserman

Reputation: 198211

image[][] images = new image[COLUMNIMAGES][ROWIMAGES];

Upvotes: 3

Related Questions