ERROR: list does not name a type (C++). I don't think so? -


so have been building on small example of classes found floating around better prepare me c++ coding assignments in future. trying compile code gives me error: "classexample.cpp:12:2: error: 'list' not name type".

the problem is, assigned it's type of rectangle* can see in code below. doing wrong?

// classes example #include <iostream> #include <stdlib.h> #include <string> #include <sstream>  using namespace std;  class setofrectangles {     list<rectangle*> rectangles; };  class rectangle {     int width, height; //class variables    public:   //method constructors     rectangle(){width = 0;  //constructor rectangle         height = 0;}     rectangle(int i, int j){width = i; height=j;}     void set_values (int,int);     string tostring();     int area() {return width*height;}     int perimeter(){return (2*width)+(2*height);} };  void rectangle::set_values (int x, int y) { //fleshing out class method   width = x;   height = y; }  string rectangle::tostring() {     /*         prints information of rectangle         demonstrates int string conversion (it's bitch)     */      std::stringstream sstm; //declare new string stream      sstm << "width = ";     sstm << width;      sstm << "\n";      sstm << "height = ";     sstm << height;          sstm << "\n";      sstm << "perimeter = ";     sstm << perimeter();      sstm << "\n";      return sstm.str(); //return stream's string instance }  int main (int argc, char* argv[]) {     if(argc != 3)     {         cout << "program usage: rectangle <width> <height> \n";         return 1;     }        else     {         rectangle rect = rectangle(2,3); //new instance, rectangle 0x0         cout << "area: " << rect.area() << "\n";         cout << rect.tostring() << endl;          //call method         rect.set_values (atoi(argv[1]),atoi(argv[2]));          cout << "area: " << rect.area() << "\n";         cout << rect.tostring() << endl;         return 0;     } } 

you need include proper header list: #include <list>

also, why including c header <stdlib.h> in c++ application? atoi? if so, should how casts in c++ in proper way. or include <cstdlib> instead (which c++ version of same header).

also, need move this:

class setofrectangles {     list<rectangle*> rectangles; }; 

to after declaration of class rectangle, or compiler won't know rectangle is.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -