c++ - expected class-name before ‘{’ token { -
i have simple program, 2 classes, inheritance, , can't work out why isn't working. it's getting on nerves.
i have in main.cpp
#include <iostream> #include "square.h" class shapeparent { protected: int width; int height; public: void setvalues(int a, int b) { width = a; height = b; } }; int main() { square small; small.setvalues(5,5); small.printarea(); // return 0; }
and in square.h
#ifndef square_h #define square_h class square: public shapeparent { public: void printarea() { // std::cout << width << std::endl; // std::cout << height << std::endl; int area = width*height; std::cout << area << std::endl; } }; #endif
i error 'expected class-name before ‘{’ token' in square.h
class shareparent shall defined before class square. name used in c+ program shall @ first defined before using.
i advice place definition of class shapeparent in separate header file example "shareparent.h"
, include header in file square.h
. example
#ifndef square_h #define square_h #include "shareparent.h" class square: public shapeparent //...
Comments
Post a Comment