#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,
The 11th Blue Bridge Cup python The real topic of the University Group National Games JavaSwing To achieve a simple Lianliankan games 【Spring Source code analysis 】42-@Conditional Detailed explanation element-ui Step on pit record 2019PHP Interview questions ( Continuously updated )PHPJava Misunderstanding —— Method overloading is a manifestation of polymorphism ? First issue 500 100 million , Set up a new Department , What is Tencent going to do ? Google chrome The browser can't open the web page , But what if other browsers can open it ? Regression of dependent variable order categories (R language )【Golang Basic series 10 】Go language On conditional sentences if