#include <iostream> #include <string> using namespace std; class Box { public:
Box(int h,int w,int l):height(h),width(w),length(l){} int volume( ){return
height*width*length;}; private: static int height; // Static data members int width; int
length; }; int main() { Box b(2,3,4); cout<<"volume is "<<b.volume()<<endl;
return 0; }

Find out what's wrong with this program ?

error  1 error C2438: “height”: Static class data cannot be initialized through a constructor  

Static data members cannot be assigned as normal data members through normal member functions , It needs to be assigned separately outside the class “int Box::height=2;”

#include <iostream> #include <string> using namespace std; class Box { public:
Box(int w,int l):width(w),length(l){} int volume( ){return
height*width*length;}; private: static int height; // Static data members int width; int
length; };int Box::height=2; int main() { Box b(3,4); cout<<"volume is
"<<b.volume()<<endl; return 0; }

Technology
©2019-2020 Toolsou All rights reserved,
In the problem of target detection “ recall Recall”,“ Accuracy Precision”Linux Page replacement algorithm C Language implementation About wechat payment body( Product description ) Problems encountered stay Vue Use in Web Worker Calculate the working days of each month c++ Memory Pointer out of bounds detection mechanism _CrtMemBlockHeadeJavaScript Medium Call and Apply Remember once EventBus Project issues caused by memory leaks Hundreds of millions of locusts rarely collide Locusts want to be self driving Heroes Java Swing JList: List box components