<br>
Mixing "new" and "delete" with "malloc" and "free" is<br>
never a good idea, but if your class doesn't contain<br>
other classes (either by reference or pointer) then<br>
you could do what you said.<br>
<br>
Just be forewarned that you are in...
<br>
I would recommend the following:<br>
<br>
result = (int*)malloc((length+l)*sizeof(int));<br>
<br>
if ( 0 == result) {<br>
exit(1); // Or whatever action you want to take.<br>
}<br>
<br>
Remember that malloc returns a void*, which you need to<br>
cast to the appropriate type.<br>
<br>...
It sure is a bad idea.<br>
<br>
malloc() and free() know nothing of constructors and destructors, which means they will not be called.<br>
<br>
That can lead to some very hard to find runtime bugs.<br>
<br>
Just to illustrate, take this example:<br>
<br>
class MyClass<br>
{<br>
public:<br>
<br>...
If you are really interested in virtual constructors, also known as factory function, I would recommend you take a look at Scott Meyers book "Effective C++ (Second Edition)", pp. 149-152.<br>
<br>
He dedicates a few pages to virtual constructors and why you would want to create one. While you...
To answer your questions:<br>
<br>
1. The reason you should use const instead of #define is<br>
that const can be type checked by the compiler, which<br>
is not the case with #define . This allows you to use<br>
the full power of the C++ compiler to help you find<br>
bugs during...
Hi there!<br>
<br>
You need to overload the input stream operator >> for <br>
your class like this:<br>
<br>
<br>
istream& operator>>(istream& in,yourClass& theClass)<br>
{<br>
in >> theClass.attribute1;<br>
in >> theClass.attribute2;<br>
.<br>
.<br>
.<br>...
In Solaris 2.5.1,<br>
<br>
getch() is in curses.h .<br>
<br>
You might want to check the specific type of UNIX you are<br>
using just to make sure it's in the same place.<br>
<br>
Hope this helps!<br>
<br>
-Mart311
Your friend's uncle is partially right.<br>
<br>
While it is true that "given the same starting point,<br>
a computer will always generate the same sequence of<br>
numbers from a random number generator", it is not true<br>
that "the random number generator does not start to <br>
evenly...
I agree with slok. You need to put your procedure<br>
declaration before you invoke it.<br>
<br>
Also, you need quotes around the string you are <br>
passing to puts. ( puts "i'm in myProc, n is $n" )
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.