C++ Multiple Static Functions With Same Name But Different Arguments <p>It appears as though I stumbled across something odd while trying to write my own wrapper for the freeglut api. Basically, I am writing my own little library to make using freeglut easier. One of the first things that I am doing is attempting to implement my own Color class which will be fed into "glClearColor". I am also having it so that you can enter the colors in manually; this means that I will have mutliple static methods with the same name but different parameters/arguments. I tried to compile this afterwards but recieved an error that makes me think that the compiler cant decide which method to use—which is odd considering the two methods in question are still different. One takes a Color3 class and the other a Color4.</p> <p>Here is some source:</p> <p>GL.H</p> <pre><code>#pragma once #include "Vector3.h" #include "Color3.h" #include "Color4.h" #include &lt;string&gt; class GL { public: static void initializeGL(int argc, char* argv); static void initializeDisplayMode(unsigned int displayMode); static void initializeWindowSize(int width, int height); static void createWindow(std::string title); static void mainLoop(); static void translate(const Vector3 &amp;location); static void translate(float x, float y, float z); static void rotate(double rotation, float x, float y, float z); static void rotate(double rotation, const Vector3&amp; axis); static void color3(const Color3 &amp;color); static void color4(const Color4 &amp;color); static void begin(); static void end(); static void pushMatrix(); static void popMatrix(); static void enable(int enableCap); static void viewport(); static void polygonMode(); static void matrixMode(); static void clearColor(const Color3 &amp;color); static void clearColor(float red, float green, float blue); static void clearColor(float red, float green, float blue, float alpha); static void clearColor(const Color4 &amp;color); static void vertex3(const Vector3 &amp;location); static void vertex3(float x, float y, float z); static void loadIdentity(); static void perspective(); static void depthFunction(); }; </code></pre> <p>GL.cpp</p> <pre><code>#include "GL.h" #include "freeglut.h" void GL::clearColor(const Color3 &amp;color) { glClearColor(color.getRed,color.getGreen,color.getBlue, 1.0f); } void GL::clearColor(float red, float green, float blue) { glClearColor(red, green, blue, 1.0f); } void GL::clearColor(float red, float green, float blue, float alpha) { } void GL::clearColor(const Color4 &amp;color) { } </code></pre> <p>And here is my compiler error:</p> <pre><code>1&gt;------ Build started: Project: GameEngineToolkit, Configuration: Debug Win32 ------ 1&gt; Main.cpp 1&gt;c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\main.cpp(47): error C2665: 'GL::clearColor' : none of the 4 overloads could convert all the argument types 1&gt; c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.h(610): could be 'void GL::clearColor(const Color4 &amp;)' 1&gt; c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.h(607): or 'void GL::clearColor(const Color3 &amp;)' 1&gt; while trying to match the argument list '(Color3 *)' 1&gt; GL.cpp 1&gt;c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getRed': function call missing argument list; use '&amp;Color3::getRed' to create a pointer to member 1&gt;c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getGreen': function call missing argument list; use '&amp;Color3::getGreen' to create a pointer to member 1&gt;c:\the capsule\c++\get\gameenginetoolkit\gameenginetoolkit\gl.cpp(8): error C3867: 'Color3::getBlue': function call missing argument list; use '&amp;Color3::getBlue' to create a pointer to member 1&gt; Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== </code></pre> <p>As you can see, it seems that the compiler cant decide between using the Color3 function or the color4 function; I dont understand why because it should be obvious which one to choose(the Color3 one is the one I am using in my main).</p> <p>As per request, here is my Color3 class:</p> <p>Color3.h</p> <pre><code>#pragma once class Color3 { public: Color3(); Color3(float red, float green, float blue); void setRed(float red); void setGreen(float green); void setBlue(float blue); float getRed(); float getGreen(); float getBlue(); Color3 getColor(); ~Color3(); private: float red; float green; float blue; }; </code></pre> <p>Color3.cpp</p> <pre><code>#include "Color3.h" Color3::Color3() { } Color3::Color3(float red, float green, float blue) { setRed(red); setGreen(green); setBlue(blue); } Color3::~Color3() { } float Color3::getRed() { return red; } float Color3::getGreen() { return green; } float Color3::getBlue() { return blue; } void Color3::setBlue(float blue) { this-&gt;blue = blue; } void Color3::setGreen(float green) { this-&gt;green = green; } void Color3::setRed(float red) { this-&gt;red = red; } Color3 Color3::getColor() { return *this; } </code></pre> <p><strong>The Solution:</strong></p> <p>Use pointers.</p> <p>GL.cpp</p> <pre><code>#include "GL.h" #include "freeglut.h" void GL::clearColor(Color3* color) { glClearColor(color-&gt;getRed(),color-&gt;getGreen(),color-&gt;getBlue(), 1.0f); } void GL::clearColor(float red, float green, float blue) { glClearColor(red, green, blue, 1.0f); } void GL::clearColor(float red, float green, float blue, float alpha) { } void GL::clearColor(Color4* color) { } </code></pre> <p>GL.H</p> <pre><code>#pragma once #include "Vector3.h" #include "Color3.h" #include "Color4.h" #include &lt;string&gt; class GL { public: static void initializeGL(int argc, char* argv); static void initializeDisplayMode(unsigned int displayMode); static void initializeWindowSize(int width, int height); static void createWindow(std::string title); static void mainLoop(); static void translate(const Vector3 &amp;location); static void translate(float x, float y, float z); static void rotate(double rotation, float x, float y, float z); static void rotate(double rotation, const Vector3&amp; axis); static void color3(const Color3 &amp;color); static void color4(const Color4 &amp;color); static void begin(); static void end(); static void pushMatrix(); static void popMatrix(); static void enable(int enableCap); static void viewport(); static void polygonMode(); static void matrixMode(); static void clearColor(Color3* color); // Use pointers instead static void clearColor(float red, float green, float blue); static void clearColor(float red, float green, float blue, float alpha); static void clearColor(Color4* color); // Same thing; no error. =P static void vertex3(const Vector3 &amp;location); static void vertex3(float x, float y, float z); static void loadIdentity(); static void perspective(); static void depthFunction(); }; </code></pre>