March 13, 1998

Member or Global Function?

Question: I have a function that takes 2 classes as arguments. Should I make the function global or inside the class? If that should be a member function, is there any rules to select which class should I place the function in? Answer: The “rules” are nearly endless, and it’s


Question: Hi,got a problem with a cast. Maybe someone out there knows how to solve it. How can I get this void pointer to act like (point to) my object?example: myClass* mc; void *vp; mc = new myClass; vp = (void *)mc; vp->some_func(); //this doesn’t work! Why! //Bjorn Answer: Because

Reading a data file in C++

Question: I’m trying to read a data file that I can read just find in Visual Basic, but the integers don’t seem to work when I use Visual C++. Note: I am new to C++example recordstruct DEPTRECORD { int DeptID; char DeptName[25] };DEPTRECORD DeptRec…….ifstream is( filename, ios::nocreate );……*) &DeptRec, sizeof(DeptRec))cout

Formatting Text

Question: I am doing a word processing programs which perform a task called center justification on one paragraph user enters–similar with the center justification function performed by MS-Word.I have to use dynamic memory manipulation and pointers. Could you give me an idea about the design?Or, Could you tell me any

C++ Linked list

Question: How would you reverse a linked list? Have looked in books at school library, and in tutorial. Hope you can point me in the right direction. Thank you for your time. Answer: The only way to directly traverse a linked list in reverse is to have the links arranged

Adding/Subtracting Time

Question: How do I add/subtract a series of time values of format hh:mm:ss (for example, 02:45:32 + 00:35:43 + and so on)? Also, how do I set the mm:ss format? Answer: You can use the RelativeTime function to add and subtract seconds from a time variable. To add minutes and

System Tray

Question: Can you program C++ to allow a program run in the system tray (next to the clock) like VB? If so, is there sample code somewhere? Answer: This task is easier to do in C than it is in VB. Unfortunately, the code to do this is a little

Queues & Stacks

Question: Though I’ve been programming in C/C++ for several years now, I’ve never understood how to build a queue or stack. I used to resort to some of the included libraries in Borland C++. But things have changed… I’m going to be moving over to a new O/S, and I

Pointers’ content reset

Question: I’ve declared a pointer to integer in file A of project. The pointer is also being used by file B of the same project. I discovered that the pointer’s value (i.e. the address which it’s pointing to) is reset to a value of NULL when it enters file B.

No more posts to show