namespaces - A bunch of weird ISO C++ forbids declaration errors -


i have header file looks follows:

1 #include <iostream>   2 #include <cassert>   3 #include <cmath>   4 #include <string>   5 #include <cstdlib>   6    7 using namespace std; //bit lazy here, have used declaration , when   8    9   10 #define true 1  11 #define false 0  12   13 namespace cartesian_plane{  14   15   16 enum shapes {linear, circular, rectangular}; //shapes considered drawing  17   18   19 struct coordinate_set{  20   21 double x;  22 double y;  23   24 };  25   26   27 struct attributes{  28   29 shapes this_figure; //line, circle or rectangle  30 unsigned short num_coordinates; //set based on figure  31 coordinate_set* coordinates; // actual points  32 int dimension1;  33 int dimension2;  34   35 };  36   37   38 attributes archive; //object store shape attributes calculations  39   40   41 bool plot (attributes obj); //method plot coordinate points,returns true or false based on whether requested shape intersects     shape drawn on caretsian plane  42   43 class shape {  44   45 public:  46 virtual bool draw () = 0;  47 virtual ~shape();  48   49 }; // abstract generating 3 shapes  50   51   52 class line: public shape{  53   54 public:  55 line(coordinate_set start, coordinate_set end);  56 ~line();  57 bool draw();  58   59 private:  60 line();  61 coordinate_set start;  62 coordinate_set end;  63 coordinate_set* p; //for plot operations on cartesian plane   64 };  65   66   67 class circle: public shape{  68   69 public:  70 circle(coordinate_set center, unsigned int radius);  71 ~circle();  72 bool draw();  73   74 private:  75 circle();  76 coordinate_set center;  77 int radius;  78 coordinate_set* p; //for plot operations on cartesian plane   79 };  80   81   82 class rectangle: public shape{  83   84 public:  85 rectangle(coordinate_set point1, coordinate_set point2);  86 ~rectangle();  87 bool draw();  88   89 private:  90 rectangle();  91 coordinate_set diagonal_vertex1;  92 coordinate_set diagonal_vertex2;  93 coordinate_set* p; //for plot operations on cartesian plane   94 };  95   96 } //end of namespace declaration  97   98  

in .cpp file, have constructor , destructor definitions shown below:

793 //constructor definitions 794  795 cartesian_plane::line(cartesian_plane::coordinate_set start, cartesian_plane::coordinate_set end):start{start}, end{end} 796 { 797  p = null; 798 } 799  800  801 cartesian_plane::circle(cartesian_plane::coordinate_set center, int radius):center{center}, radius{radius} 802 { 803  p = null; 804 } 805  806 cartesian_plane::rectangle(cartesian_plane::coordinate_set point1, cartesian_plane::coordinate_set point2):diagonal_vertex1{point1}, dia    gonal_vertex2{point2} 807 { 808  p = null; 809 } 810  811  812 //destructor definitions 813  814 cartesian_plane::~line(){delete p; p = null; } 815 cartesian_plane::~circle(){delete p; p = null; } 816 cartesian_plane::~rectangle(){delete p; p = null; } 

for above definitions, bunch of weird compilation errors, when compiling using command **g++ -ggdb -cpp program.cpp**:

program.cpp:795:97: error: iso c++ forbids declaration of ‘line’ no type [-fpermissive] program.cpp:795:97: error: ‘int cartesian_plane::line(cartesian_plane::coordinate_set, cartesian_plane::coordinate_set)’ should have been declared inside ‘cartesian_plane’ program.cpp: in function ‘int cartesian_plane::line(cartesian_plane::coordinate_set, cartesian_plane::coordinate_set)’: program.cpp:795:99: error: constructors take member initializers program.cpp:795:99: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:795:113: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:797:2: error: ‘p’ not declared in scope program.cpp: @ global scope: program.cpp:801:75: error: iso c++ forbids declaration of ‘circle’ no type [-fpermissive] program.cpp:801:75: error: ‘int cartesian_plane::circle(cartesian_plane::coordinate_set, int)’ should have been declared inside ‘cartesian_plane’ program.cpp: in function ‘int cartesian_plane::circle(cartesian_plane::coordinate_set, int)’: program.cpp:801:77: error: constructors take member initializers program.cpp:801:77: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:801:93: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:803:2: error: ‘p’ not declared in scope program.cpp: @ global scope: program.cpp:806:106: error: iso c++ forbids declaration of ‘rectangle’ no type [-fpermissive] program.cpp:806:106: error: ‘int cartesian_plane::rectangle(cartesian_plane::coordinate_set, cartesian_plane::coordinate_set)’ should have been declared inside ‘cartesian_plane’ program.cpp: in function ‘int cartesian_plane::rectangle(cartesian_plane::coordinate_set, cartesian_plane::coordinate_set)’: program.cpp:806:108: error: constructors take member initializers program.cpp:806:108: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:806:134: warning: extended initializer lists available -std=c++11 or -std=gnu++11 [enabled default] program.cpp:808:2: error: ‘p’ not declared in scope program.cpp: @ global scope: program.cpp:814:18: error: scope ‘cartesian_plane’ before ‘~’ not class-name program.cpp:815:18: error: scope ‘cartesian_plane’ before ‘~’ not class-name program.cpp:816:18: error: scope ‘cartesian_plane’ before ‘~’ not class-name 

i want make confession here. originally, had stupidly declared enum in header file follows:

enum shapes {line, circle, rectangle}; 

for above declaration, got same errors reproduced above, additional explanation line, circle , rectangle enum members. based on that, realized compiler not distinguish between class line , enum member line due same naming. subsequently, changed enum declaration present

enum shapes {linear, circular, rectangular}; 

hoping that should take care of errors. apparently not. errors, impression oddly, compiler trying read source code obsolete cache, rather changed source file. tried rebooting machine (i working on fedora linux) no avail. suggestions appreciated.

tia

vinod

in implementation,

cartesian_plane::line(...) { ... } 

should be

cartesian_plane::line::line(...) { ...} 

same issue applies destructors.

it because cartesian_plane::line class name. no function name specified when wrote cartesian_plane::line(...) {...}.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -