Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. Mart311

    Allocation of memory with using different operators

    <br> Mixing &quot;new&quot; and &quot;delete&quot; with &quot;malloc&quot; and &quot;free&quot; 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...
  2. Mart311

    Malloc help!!!!!!!!!!

    <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>...
  3. Mart311

    Malloc help!!!!!!!!!!

    I have to agree with Mike.<br> <br> Could you post the program so that we can take a look at it?<br> <br> Thanks!<br> <br> -Mart311
  4. Mart311

    Allocation of memory with using different operators

    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>...
  5. Mart311

    Virtual Constructors

    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...
  6. Mart311

    const vs #defines

    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...
  7. Mart311

    READING FROM A FILE!

    Hi there!<br> <br> You need to overload the input stream operator &gt;&gt; for <br> your class like this:<br> <br> <br> istream& operator&gt;&gt;(istream& in,yourClass& theClass)<br> {<br> in &gt;&gt; theClass.attribute1;<br> in &gt;&gt; theClass.attribute2;<br> .<br> .<br> .<br>...
  8. Mart311

    lost good subfunction, "getch" in stdio.h

    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
  9. Mart311

    Printing to a particular spot on a line in C++

    How about this:<br> <br> int spaces = 30;<br> <br> for (int i=0;i&lt;spaces;i++) cout &lt;&lt; " ";<br> <br> cout &lt;&lt; yourString &lt;&lt; endl;<br> <br> -Mart311
  10. Mart311

    Random Number Generator

    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...
  11. Mart311

    call a procedure in tcl/tk

    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" )

Part and Inventory Search

Back
Top