This declaration has no storage class or type specifier in C++ -
i have multiple classes in program .
a) when create object of class in class getting no error when use object call function above error .
b)also if create object of class , call function using in constructor of class no error .
c) cout function not work in body of class except when put function
d) main class able of these , not getting error .
it great hear . thank in advance .
following code : these 2 classes in cpp. facing no problems except using object after creating . code huge posted . can done in main not in other classes why ?
#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cstdlib> #include <vector> #include <map> using namespace std; class message { public: void check(string side) { if(side!="b"&&side!="s") { cout<<"side should either buy (b) or sell (s)"<<endl;; } } }; class orderbook { public: string side; orderbook() //no error if define inside constructor message m; //no error while declaring m.check(side); //error when write m. or m-> };
this mistake:
m.check(side);
that code has go inside function. class definition can contain declarations , functions.
classes don't "run", provide blueprint how make object.
the line message m;
means orderbook
contain message
called m
, if later create orderbook
.
Comments
Post a Comment