Note that there are some explanatory texts on larger screens.

plurals
  1. POInititalze vector of custom class?
    text
    copied!<p>I have the following the class: </p> <pre><code>//Rectangle.h #include "Point.h" class Rectangle{ public: Rectangle(); void setWidth(int); void setHeight(int); int getWidth(); int getHeight(); void draw(Point); private: int m_width; int m_height; }; //Rectangle.cpp #include &lt;Windows.h&gt; #include &lt;iostream&gt; #include &lt;GL/Gl.h&gt; #include &lt;GL/Glu.h&gt; #include &lt;GL/Glut.h&gt; #include "Rectangle.h" #include "Point.h" //constructor Rectangle::Rectangle(){ } int Rectangle::getHeight(){ return m_height; } int Rectangle::getWidth(){ return m_width; } void Rectangle::setHeight(int a_height){ m_height = a_height; } void Rectangle::setWidth(int a_width){ m_width = a_width; } void Rectangle::draw(Point center){ int pointWidth = m_width / 2; int pointHeight = m_height / 2; std::cout &lt;&lt; "drawing rectangle at" &lt;&lt; center.getX() &lt;&lt; ", " &lt;&lt; center.getY() &lt;&lt; std::endl; glColor3f(1, 1, 0); glBegin(GL_POLYGON); glVertex2i( center.getX() - pointWidth, center.getY() - pointHeight ); glVertex2i( center.getX() + pointWidth, center.getY() - pointHeight ); glVertex2i( center.getX() + pointWidth, center.getY() + pointHeight ); glVertex2i( center.getX() - pointWidth, center.getY() + pointHeight ); glEnd(); } </code></pre> <p>And then I have the following in main.cpp. The problem is with the line <code>vector&lt;Rectangle&gt; rectangles;</code> I get the following error:</p> <blockquote> <p>std::vector : Rectangle is not a valid template type argument for parameter '_Ty'</p> </blockquote> <pre><code>#include &lt;Windows.h&gt; #include &lt;math.h&gt; #include &lt;string&gt; #include "Rectangle.h" #include "Point.h" #include "Pentagon.h" #include "Star.h" #include "StringManip.h" #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;vector&gt; #include &lt;GL/Gl.h&gt; #include &lt;GL/Glu.h&gt; #include &lt;GL/Glut.h&gt; using namespace std; // Function prototypes for callbacks void myDisplay(void); void myInit(); void openFile(string); Point point; vector&lt;Point&gt; points; vector&lt;Rectangle&gt; rectangles; vector&lt;Pentagon&gt; pentagons; vector&lt;Star&gt; stars; </code></pre> <p>I'm at a loss for what's up. I think I've done my class correctly. If anyone could tell me what's wrong, I'd appreciate it. </p> <p>Here's Point.h and Point.cpp</p> <pre><code>//Point.h #ifndef POINT_H #define POINT_H class Point { public: //default constructor Point () { m_xCoord = 0; m_yCoord = 0; } //set x and y void setX(int a_x); void setY(int a_y); //get x and y int getX(); int getY(); //change x and y by a specified value. void changeX(int a_x); void changeY(int a_y); private: int m_xCoord; int m_yCoord; }; #endif //Point.cpp #include "Point.h" void Point::setX(int a_x){ m_xCoord = a_x; } void Point::setY(int a_y){ m_yCoord = a_y; } int Point::getX(){ return m_xCoord; } int Point::getY(){ return m_yCoord; } void Point::changeX(int a_x){ m_xCoord += a_x; if(m_xCoord &lt; 0){ m_xCoord = 0; } } void Point::changeY(int a_y){ m_yCoord += a_y; if(m_yCoord &lt; 0){ m_yCoord = 0; } } </code></pre>
 

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