Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ inner classes not compiling
    primarykey
    data
    text
    <p>I have a Class called Song with Inner class Creator . Below is the Song.h File. Please ignore the comments.</p> <pre><code>#ifndef SONG_H #define SONG_H #include &lt;iostream&gt; class Song { public: class Creator{ public: //Creator&amp; name(const std::string name){}; void name(const std::string name){}; //std::string getName(){}; }; private: std::string mName; }; #endif // SONG_H </code></pre> <p>and here is Song.cpp class</p> <pre><code>#include "Song.h" using std::string; //using Song::Creator; //Song::Creator&amp; Song::Creator::name(const string name) void Song::Creator::name(const string name) { mName=name; std::cout&lt;&lt;name; //return *this; } //string Creator::getName() //{ //return mName; //} </code></pre> <p>and the main class</p> <pre><code>#include &lt;iostream&gt; #include "Song.h" int main() { Song::Creator sc; sc.name("vickey"); //std::cout&lt;&lt;sc.getName(); return 0; } </code></pre> <p>On compilation it throws </p> <pre><code>/home/vickey/qtprojects/innerClass-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Release/../innerClass/Song.cpp:6: error: redefinition of 'void Song::Creator::name(std::string)' </code></pre> <p>and if I change the name function to </p> <pre><code>void Creator::name(const string name) { mName=name; std::cout&lt;&lt;name; //return *this; } </code></pre> <p>I get this error</p> <pre><code>/home/vickey/qtprojects/innerClass-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Release/../innerClass/Song.cpp:6: error: 'Creator' has not been declared </code></pre> <p>what is that I m doing wrong ? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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