Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may want to pick up <a href="https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list">a good C++ book</a> to learn from, as the things you're getting wrong are fundamental to the language.</p> <hr> <p>Class declarations need a <code>class</code> keyword preceeding the class name:</p> <pre><code>class TPlayer { private: // ... </code></pre> <p>You need this because the compiler needs to know if you're talking about a <code>class</code> or a <code>struct</code> or a <code>union</code> or an <code>enum</code>, etc. Otherwise you end up with lots of errors like you got.</p> <hr> <p>Your member functions also need to be prefixed with <code>TPlayer::</code>, like how you did with the constructors and destructor. These are needed so that the compiler knows that they are part of the <code>TPlayer</code> class.</p> <pre><code>TPlayer::TPlayer() { } TPlayer::~TPlayer() { } void TPlayer::SetName(char *_name) { } char TPlayer::GetName(void) { } </code></pre> <hr> <p>There's no need to <code>delete</code> class members that you didn't allocate yourself.</p> <pre><code>~TPlayer::TPlayer() { // These are not needed. The variables name, hp, dmg, and wep // were allocated when you created an instance of TPlayer. These // will go away by themselves when the destructor is called. //delete name; //delete hp; //delete dmg; //delete wep; // The exceptions to the above rule are things that are dynamically // allocated. For example, you must delete[] everything that // you new[]'ed, and you must fclose() all file handles you // get from fopen(). If you consistently use the RAII idiom, // then you won't have to worry about these "exceptions". } </code></pre> <p>In fact, modern C++ programs nowadays rarely need to use <code>delete</code> in application code. The <a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization" rel="nofollow noreferrer">"Resource Acquisition Is Initialization" (RAII)</a> idiom allows you to not have to worry about <code>delete</code>-ing things a vast majority of the time. Standard library facilities like <code>std::vector</code> use the RAII idiom to manage the array memory.</p> <hr> <p>Note that <a href="https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier">there are rules regarding the use of identifiers beginning with underscores</a>. You may need to be aware of them.</p> <hr> <p>For the sake of learning by example, here's an valid sample class:</p> <p><strong>foo.h</strong></p> <pre><code>#ifndef FOO_H #define FOO_H class Foo { public: Foo(); ~Foo(); void Set(int n); int Get() const; private: int n; }; #endif </code></pre> <p><strong>foo.cpp</strong></p> <pre><code>#include "foo.h" Foo::Foo() : n(0) { } Foo::~Foo() { } void Foo::Set(int n) { this-&gt;n = n; } int Foo::Get() const { return n; } </code></pre>
    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. 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.
 

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