Note that there are some explanatory texts on larger screens.

plurals
  1. POConstructor w/Multiple Arguments in Constructor list not working C++
    text
    copied!<p>I'm trying to compile class A, which has a member of class B, where class B has no default constructor and its only constructor requires multiple arguments. Simple, right? Apparently not...</p> <p>Class A:</p> <pre><code>class SessionMediator { public: SessionMediator() : map_(16,100,100) {} Tilemap map_, background_, foreground_; }; </code></pre> <p>Class B:</p> <pre><code>struct Tile2D; class Tilemap { public: Tilemap(const unsigned int tile_size, const unsigned int width, const unsigned int height) : tiles_(NULL), tile_size_(tile_size) { Resize(width, height); } inline void Resize(const unsigned int width, const unsigned int height) { /* Allocate tiles &amp; assign to width_, height_... */ } unsigned int tile_size_, width_, height_; Tile2D* tiles_; }; </code></pre> <p>I am instantiating SessionMediator like so:</p> <pre><code>int main(int argc, char** argv) { SessionMediator session; return 0; } </code></pre> <p>This is the error I am getting. I'm compiling in XCode on Mac OS 10.5.8 and the compiler is g++:</p> <pre><code>session_mediator.h: In constructor 'SessionMediator::SessionMediator()': session_mediator.h:19: error: no matching function for call to 'Tilemap::Tilemap()' tilemap.h:31: note: candidates are: Tilemap::Tilemap(unsigned int, unsigned int, unsigned int) tilemap.h:26: note: Tilemap::Tilemap(const Tilemap&amp;) session_mediator.h:19: error: no matching function for call to 'Tilemap::Tilemap()' tilemap.h:31: note: candidates are: Tilemap::Tilemap(unsigned int, unsigned int, unsigned int) tilemap.h:26: note: Tilemap::Tilemap(const Tilemap&amp;) (Duplicate of above here) Build failed (2 errors) </code></pre> <p>I wrote a short compilable example doing basically the same thing, to try to figure out what exactly I was doing wrong, which compiles just fine with no errors in g++:</p> <pre><code>class A { public: A(int x, int y, int z) : x_(x), y_(y), z_(z) {} int x_, y_, z_; }; class B { public: B() : m_a(1,2,3) {} A m_a; }; int main(int argc, char **argv) { B test; return 0; } </code></pre> <p>Why does it fail in the first example? The 3 arg constructor for Tilemap (in Ex#1) is being called in the same way that the 3 arg constructor for A is being called (in Ex#2).</p> <p>The code seems pretty much identical to me in the two examples.</p>
 

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