There's nothing wrong with it, but it's very dangerous if you're not careful.
On the other hand, your code is wrong. What's the pointer type of (another+offset)? It's actually a pointer to SomeClass, not an int, so you should at least cast the pointer to (int *):
*((int *)(another + offset)) = 3;
The offset is another thing to watch out for, because it's always in units of the type the pointer points to. In short, when int is 4 bytes long, adding 1 to a (int *)
pointer will actually add 4 to it, so it's better to cast any pointer to (char *) before doing calculations.
So for your example:
SomeClass* foo = new SomeClass();
int offset = (char *)&(foo->bar) - (char *)foo;
SomeClass* another = new SomeClass();
*((int *)((char *)another+offset)) = 3; // try to set bar to 3