New course! Every coder should learn Generative AI!
Try a free lesson0
The code below is working on c++98 but not on c++11 or c++14...please help
#include <iostream> using namespace std; class system { double amount; public: system(double a) { amount = a; cout << amount; } }; int main() { double n; cout << "Please enter the amount number : "; cin >> n; system obj(n); } the error is :- source_file.cpp: In function 'int main()': source_file.cpp:21:14: error: expected ';' before 'obj' system obj(n); ^~~ source_file.cpp:21:20: warning: statement is a reference, not call, to function 'system' [-Waddress] system obj(n); ^ source_file.cpp:21:20: warning: statement has no effect [-Wunused-value]
4 Answers
0
You need to use capital letters for the first letter of your class, change 'system' to 'System'
+ 4
Actually, system is a build-in function ( which you shouldn't be using anyway ) defined in cstdlib, which is included through iostream.
So you have a name collision here.
But just like jtrh said, you should name the class starting with a capital.
+ 1
thanks alot jtrh 😃😃
but why is it so?
why can't I write in lowercase?
Is it a convention in new c++?
+ 1
It was optional to follow naming conventions in old c++ but now I guess it is compulsory. It's good practice though