#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,
QQ Login interface implementation code implementation mysql Addition, deletion, modification and query of database JAVA Experiment 4 set and functional programming experiment about String How to create objects VHDL——4 choose 1 Data selector C language ( Guess numbers games ) Blue Bridge Cup MCU advanced module --NE555 I don't memorize eight part essays , You go to the interview ? Hill sorting of sorting algorithm ——c++ realization python What does built-in function mean _python What are the built-in functions