Hello there people, I'm trying to create a backgammon game using C++ and I am getting an annoying error

error C2228: left of '.length' must have class/struct/union

Here is the code it is refering to

diceArray = new int[4];
for(int i = 0;i<diceArray.length;i++)
diceArray = d1;

I have declared diceArray as a pointer

int* diceArray; //stores dice rolls

can anyone help?

Also i get this error

error C2440: 'return' : cannot convert from 'int *' to 'int'

When trying to use this code

int board2::getDiceArray()
{
//returns the diceArray[]
return diceArray;
}

I was converting from Java initially

Any help will be greatly appreciated.

Ok I now know that int is not an object in c++ therefore does not have a method length.

But how do I go about sorting this? Someone said something about use stl-array, build your own array class or just pass the length as integer in addition to the actual array but I don't know how to do that :s

I was converting from Java initially

That explains this error:

for(int i = 0;i<diceArray.length;i++)

There have been several threads on Daniweb regarding whether you can determine the length of an array from the array itself in C++ and they've almost all said that you can't do it (I think at some point someone pointed out a way to do it that worked, but I can't find the thread right now.). Anyway, even if you can do it, you definitely can't do it with length like you can with Java.

int board2::getDiceArray()
{
//returns the diceArray[]
return diceArray;
}

I think this would be an error in Java as well. Seems like it should be this:

int* board2::getDiceArray()
{
//returns the diceArray[]
return diceArray;
}

Ok I now know that int is not an object in c++ therefore does not have a method length.

But how do I go about sorting this? Someone said something about use stl-array, build your own array class or just pass the length as integer in addition to the actual array but I don't know how to do that :s

You can write your own sort or you can use sort from algorithm :

http://www.cplusplus.com/reference/algorithm/sort.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.