QueryCAT Logo
Search 5,000,000+ questions and answers.

Frequently Asked Questions

Should you use the this pointer in the constructor?

Constructors, C++ FAQ Lite
Some people feel you should not use the this pointer in a constructor because the object is not fully formed yet. However you can use this in the constructor (in the {body} and even in the initialization list) if you are careful. Here is something that always works: the {body} of a constructor (or a function called from the constructor) can reliably access the data members declared in a base class and/or the data members declared in the constructor's own class.

What is a constructor?

snitfaq - Snit's Not Incr Tcl, OO system
In object-oriented programming, an object's constructor is responsible for initializing the object completely at creation time. The constructor receives the list of options passed to the snit::type command's create method and can then do whatever it likes. That might include computing instance variable values, reading data from files, creating other objects, updating type and instance variables, and so forth.

How do I call the constructor?

FAQ
The Polynomial(int d, double *coefs) constructor is invoked when an object of type Polynomial is defined using the appropriate arguments. For example, double co[] = { 1.2, 3.4, 5.6 }; Polynomial p(2, co); constructs p to represent 5.6x2 + 3.4 x + 1.2.

Why I deleted a pointer, then use it, I still get the same data?

FAQ on C/C++/Unix by Roseanne Zhang, Java Programmer Certifi...
Yes, sometimes, it still can be used to get the same value, sometimes it does not. Sometimes, you will get a segmentation error. The language does not check the validity of the pointer. The programmer is responsible to use the pointers responsiblely. That is one problem of c/c++, which are not a safe language, but it is highly efficient! The following sample program will demonstrate the concepts.

What is a far pointer? where we use it?

OOPS FAQ - Page 6
Latest Answer: near, far pointers are the types of pointers in C. By using these pointers we can directly access me...

What Is A Pointer?

Windows Basics
A pointer is the arrow you use to choose things on screen. Since the Shortcut is simply a pointer to a specific program or file, you can delete the shortcut or remove it from the Desktop without actually deleting the program or file.

Why do we need a constructor in a servlet if we use the init method?

jGuru: Servlets FAQ Home Page
Even though there is an init method in a servlet which gets called to initialise it, a constructor is still required to instantiate the servlet. Even...

Is a null statement a null pointer?

Infrequently Asked Questions in comp.lang.c
No. A null pointer is a pointer where all of the address bits are zero (no matter what the segment bits are), and can be obtained by typing '(char *) (int) 0'. A null statement is not a pointer to anything. They are not interchangeable, although you can combine them to get an effectively-null statement, such as NULL;. This does not buy you anything. [a] Send large donations, checks, and money orders to the author of the FAQ, or the moderator of the group, whichever you prefer.

What is a type constructor?

snitfaq - Snit's Not Incr Tcl, OO system
A type constructor is a body of code that initializes the type as a whole, rather like a C++ static initializer. The body of a type constructor is executed once when the type is defined, and never again.

How do I define a constructor?

snitfaq - Snit's Not Incr Tcl, OO system
A constructor is defined by using the constructor statement in the type definition. Suppose that it's desired to keep a list of all pedigreed dogs. The list can be maintained in a type variable and retrieved by a type method. Whenever a dog is created, it can add itself to the list--provided that it's registered with the American Kennel Club.

Can constructor be overridden?

JavaChina, SCJP Questions and Answers by Roseanne Zhang (2)
Can you explain the result of the following example? Oh, my! class Base { public boolean foo(Base b) { return true; } } class Sub extends Base { public boolean foo(Sub s) { return false; } } public class Test { public static void main(String argv[]) { Base bb = new Base(); Base bs = new Sub(); Sub ss = new Sub(); System.out.println(bb.foo(bb)); //true System.out.println(bs.foo(bs)); //true ??? System.out.println(bs.foo(ss)); //true ??? System.out.println(bs.foo(bb)); //true ??? System.out.

Can I use static object instead of static pointer inside the singleton definition?

FAQ on C/C++/Unix by Roseanne Zhang
This code is actually the same as GoF's book. The singleton pattern is from many many programmers' industrial practice. Don't change it unless you are abosolute sure what you are doing. Just think a scenario, you have several huge different singletons using 2M or more memory each, and they are only needed in ~5 minutes once or once a day, however, your program is going to run 5 years continuously by 24*7.

Can I use a pointer to class/struct Node as a data member in the above question?

FAQ on C/C++/Unix by Roseanne Zhang, Java Programmer Certifi...
It is the programmer's responsibility to make sure your recursion code have a exit point!!! See the following code (borrowed from above question), no compiling errors, no linking errors, but the program will never print out the "after". struct Node { int num; Node *next; Node() { next = new Node(); //Infinite recursion!!! } }; int main() { printf("before\n"); Node a; //run out of memory, soon be dead! printf("after\n"); }

How unsafe is it to use (assign, compare) a pointer value after it's been freed?

Memory Allocation
When you call free, the memory pointed to by the passed pointer is freed, but the value of the pointer in the caller probably remains unchanged, because C's pass-by-value semantics mean that called functions never permanently change the values of their arguments. (See also question 4.8.) A pointer value which has been freed is, strictly speaking, invalid, and any use of it, even if it is not dereferenced (i.e.

If NULL and 0 are equivalent as null pointer constants, which should I use?

Null Pointers
Many programmers believe that NULL should be used in all pointer contexts, as a reminder that the value is to be thought of as a pointer. Others feel that the confusion surrounding NULL and 0 is only compounded by hiding 0 behind a macro, and prefer to use unadorned 0 instead. There is no one right answer. (See also questions 9.4 and 17.10.) C programmers must understand that NULL and 0 are interchangeable in pointer contexts, and that an uncast 0 is perfectly acceptable.

How do I create and use an array of pointer-to-member-function?

Pointers to member functions, C++ FAQ Lite
Note: #define macros are evil in 4 different ways: evil#1, evil#2, evil#3, and evil#4. But they're still useful sometimes. Feel ashamed, feel guilty, but when an evil construct like a macro improves your software, use it.
More Questions >>

© Copyright 2007-2012 QueryCAT
About • Webmasters • Contact