Thanks for the answers! Here come more questions...
1. I don't understand what exactly is going on with 64-bit programming. Some documents say long is 64bit, others say it's 32bit and long long is 64. I'd like to know exactly which name I need to use for a 64-bit integer( In case it varies depending on compiler or OS, I can simple define my own data type and typedef it differently depending on the compiler/OS...)
2. Can a (stand-alone, without any inheritance or polymorphism) class have only function members? If yes, does it have limitations? Which? Or is it just like an object/variable with size of 0 bytes? And can a pointer point to such an object?
3. These is a class template called
template<class T> MyClass;
. MyClass has a member function called func(). For some types passed as T, I'd like func() to have different implementations, not the general one. The question is whether this code is enough:
1 2 3 4 5 6 7 8 9 10 11
|
template<class T>
void MyClass<T>::func()
{
/* general implementation */
}
template<>
void MyClass<int>::func()
{
/* a different implementation specific to T=int */
}
|
MyClass itself does not have a specialization. It only has the general class definition, while func() has a special definition for int. Is it legal?
4. There is a global pointer
int* globPtr;
. There is a global function func() that uses a local pointer
int* locPtr;
. func() does three things: it allocates dynamic memory with
locPtr=new int [5];
and then copies locPtr into globPtr:
globPtr=locPtr;
. main() executes func() and then tries to set the dynamic array through b. Will it work or the dynamic memory is freed when func() ends? I'm asking because I got contradicting answers to the question "does dymanic memory get automatically deleted before the program ends". One answer is no, the other is that the memory is deleted when the pointer used with
new
is deleted/gets out of scope.
5. Is a partial specification of a partial specification allowed? for example, for
template<class A, class B, class C> MyClass;
, can I define the three different specifications
template<int,B,C>
,
template<int,float,C>
and
template<int,float,char*>
? Will the compiler recognize which is a specific case of which?
6. Can a typecasting operator function be global or it has to be a member function? And it be a static member? And in general, can operator functions be static members? If yes, are there any limitations or special rules for them?
7. If a class has an operator bool() function, can an object of this class be alone inside an
if statement?
8. Can a member of a class template point to another instantiation, for example
template<class T> MyClass
having a
MyClass<int>* ptr;
or
template<class T, class U> OtherClass
having a
OtherClass<U,T>* ptr;
, etc. ?
9. There are three floats: a,b, and c. a*b/c gives a result slightly bigger than a*(b/c). Why? Does it mean I should generally try to use division as the last operation whenever possible in order to have minimal round-off?
10. There's
template<class T> void func(T arg);
. One of the lines inside func() contains the expression
arg.MemberFunc()
. Does it mean that every class which defines a public member function (either static or non-static) without parameters called MemberFunc() can be passed as T while passing any other class will generate an error?
11. What is "big-endian" and "little-endian" ? Which OS/processors are big-endian and which are little-endian?