Saturday, 15 June 2013

class - Error: Expected a Type Specifier. C++ Inheritence -



class - Error: Expected a Type Specifier. C++ Inheritence -

i've been working on creating shape class files class, , until 15 additional lines of code, going well. i'm getting 1 of standard "expected type specifier" when create 'rectangle' object. creating objects of other 2 classes (triangle , circle) work perfectly. noticed bugged out added sec vector (shapestest2), maybe has that?

specifically, lines in question are:

shapes.push_back(new rectangle(1, 2, 3, 4, blue)); shapestest2.push_back(new rectangle(11, 22, 33, 44, black));

the error list says:

intellisense: expected type specifier 29 intellisense: expected type specifier 30 error 1 error c2661: 'std::vector<_ty>::push_back' : no overloaded function takes 5 arguments 31 error 2 error c2143: syntax error : missing ';' before ')' 31 error 3 error c2061: syntax error : identifier 'rectangle' 31

anyways, here's code in main.cpp file.:

// main.cpp - shape class test programme // written _______ #include <vector> #include <windows.h> #include "circle.h" #include "triangle.h" #include "rectangle.h" using namespace std; void main() { // container of shapes vector<shape*> shapes; vector<shape*> shapestest2; // used sec test case of move , scale. // must allocate object on heap circle *mycircle = new circle(10, 10, 100, red); shapes.push_back(mycircle); // create new, unnamed stack-allocated instance of circles , push_back() vector shapestest2.push_back(new circle(20, 20, 20, red)); // populate container 2 rectangles shapes.push_back(new rectangle(1, 2, 3, 4, blue)); shapestest2.push_back(new rectangle(11, 22, 33, 44, black)); // populate container 2 triangles shapes.push_back(new triangle(3, 4, 5, 7, 15, 4, black)); shapestest2.push_back(new triangle(6, 7, 9, 8, 43, 15, green)); // there's more file, time pops up, , rest // messing around vector<shape*>. figured i'd seek , save time , // space posting what's needed, if think error caused // code below, inquire me , i'll upload rest of main.cpp file }

and reference, here's rectangle.h file:

#pragma 1 time #include <string> #include "shape.h" using namespace std; // enum colors = {red, blue, green, black, white}; located in "shapes.h" class rectangle : public shape { public: rectangle(int x, int y, int width, int height, colors color) : shape(x, y, color) { width = width; height = height; } virtual void scale(float scalefactor) { width = int(width*scalefactor); height = int(height*scalefactor); } virtual void draw() const // const b/c doesn't alter radius, x, y, nor color { cout << "rectangle of width " << width << " , height " << height << " top left corner @ (" << x << ", " << y << ") , color " << getcolor() << ".\n" << endl; } private: int width; int height; };

thanks help guys, i've tried reading through other questions , looked people had forgotten '#include "_"' part of it.

the cause of error sort of name conflict caused inclusion of windows.h. remove line

#include <windows.h>

and compiles.

edit: avoid such conflict can place classes in namespace. in header write like:

namespace foo { class rectangle { ... }; }

c++ class inheritance compiler-errors identifier

No comments:

Post a Comment