Interviewer asks, 'What else?'
Above differences looks sufficient, but, there is more that interviewer expects. What is that ?
We cannot have,
template <\struct type\> /* ignore slash */
struct ABC{...};
Like,
template <\class type\> /* ignore slash */
class ABC{...};
Because templates do not offer backward C compatibilty.
He asks again, 'What else ?' { still more expecting ?...}
The use of one-element array at the end of a struct to allow individual struct objects to address variable-size array:
strcut ABC
{
int s;
char arr[1];
};
struct ABC* pAbc = (struct ABC*)malloc(sizeof(struct ABC)+strlen(string)+1);
strcpy(pAbc->arr, string);
This may or may nto translate well when placed within a class declaration that specifies multiple access sections containing data, derives from another class, or defines virtual functions.
Otherwise, struct is same as class... struct offers virtual functions, inheritance, ctor-dtor..everything what class offers.

No comments:
Post a Comment