can u please help me with my assignment

I need to create new type using new class -Myint- which is tepical to int type but the new one must be 10 bytes long insteade of 4 bytes

so the quesion is how to set the size of my new class objects

thanks ...

Does an instance of the class have to be exactly ten bytes always, or do you actually just need to make an int class that can handle 2^80 possible values (i.e. 10 bytes' worth of values)?

my class must be an inhancement of the int type in the aspect of digits that must be handeled and prosessed

actualy I have an idea but I am not sure about it and here it is :
why dont I make this class with three data members two of them are integars and one is short so the object is 10 bytes

On a 64-bit system, an int is often 8 bytes anyway, so if you haven't been told to assume that an int is four bytes, you'll be making something that wouldn't work on a 64-bit system. You also have to worry about padding; the compiler can add blank space in the middle of a class' members to make memory access easier, unless you force it not to.

The size can also depend on the order of the member variables, and aspects like inheritance and virtual functions. Ultimately, the compiler will do whatever it likes, and is allowed to do whatever it likes, and if you end up with a class that takes up ten bytes exactly there's no guarantee it will stay that way on other systems or with other compilers.

As it is, what you're describing makes no sense at all anyway. What is the actual, exact question or problem. Does it really say "you must make a class which will take up exactly ten bytes of memory"? That's just crazy. If it said "you must be able to handle a ten byte integer" that would make a lot more sense.

If it really must be ten bytes long, make it a char array of ten chars. A char is guaranteed to be one byte, always.

thanks alot
actually my teacher gave me a hint abot making the char array

the thing which I didn't know is why when I use the "sizeof()" function whith only short I get 2 and with int I get 4 but with a class of 2 int and 1 short I get 12 but naw I think u have explained the reason so many thanks ...

If you need it to handle atleast 10 byte integers, I would probably just use 2 uint64_t's. It would be much faster then an array of chars, and the code would be nice and simple.

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.