Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Where to start? This has a lot of errors.</p> <ol> <li><p>Don't have "using namespace std;", it clutters the global namespace. Rather, use std::list, std::cin, etc. using the namespace to identify the specific object or class.</p></li> <li><p>In the exception class, don't write your own <code>what()</code> method. Just initialise the base class in the constructor.</p> <pre><code>class EPilaVacia : public std::exception { public: EPilaVacia() : std::exception("Error: Pila Vacía") { } }; </code></pre></li> <li><p>I assume that the class Pila is just a learning exercise. In real life you would use <code>std::stack</code>, not make your own.</p></li> <li><p>If you are implementing the stack with a list, you don't need a "max" parameter.</p></li> <li><p>Don't allocate the list dynamically, that is silly. Just use <code>std::list&lt;T*&gt; ila;</code></p></li> <li><p>You don't need "cont". Use <code>ila.size();</code></p></li> <li><p>Don't make the functions like apilar() virtual. The list is private, so subclasses cannot access it, thus the methods cannot be overriden. Also, you don't have a virtual destructor, so inheritance is probably a bad idea.</p></li> <li><p>void apilar(T t) is a disaster. You pass t by value, then store the address of the parameter, which then goes out of scope. The function is unnecessary, lose it.</p></li> <li><p>Don't put "throw (EPilaVacia)" in method declarations. No compiler implements it and it is deprecated in the new C++11 standard.</p></li> <li><p>In tope(), use ila.back(), not ila.pop_back().</p> <pre><code>T tope() const { if(ila.empty()) { throw EPilaVacia(); } else { return *ila.back(); } } </code></pre></li> <li><p>In desapilar(), don't use clear as it will empty out the stack. Use something like this</p> <pre><code>T&amp; desapilar() { if(ila.empty()) { throw EPilaVacia(); } else { T *pt = ila.back(); ila.pop_back(); return *pt; } } </code></pre></li> <li><p><strong>NEVER</strong> use <code>system("Pause");</code> Use <code>std::cin.get();</code></p></li> <li><p>The objects you allocate with <code>new</code> are never deleted. You have a memory leak.</p></li> </ol> <p>There are probably more, but that should get you started. Note: I've scrawled this down quickly. There are probably errors above, so check my code, don't just copy it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload