The code below is working on c++98 but not on c++11 or c++14...please help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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]

24th Oct 2018, 8:08 AM
Rashim Narayan Tiku
Rashim Narayan Tiku - avatar
4 Answers
0
You need to use capital letters for the first letter of your class, change 'system' to 'System'
24th Oct 2018, 8:18 AM
jtrh
jtrh - avatar
+ 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.
24th Oct 2018, 9:11 AM
Dennis
Dennis - avatar
+ 1
thanks alot jtrh 😃😃 but why is it so? why can't I write in lowercase? Is it a convention in new c++?
24th Oct 2018, 8:23 AM
Rashim Narayan Tiku
Rashim Narayan Tiku - avatar
+ 1
It was optional to follow naming conventions in old c++ but now I guess it is compulsory. It's good practice though
24th Oct 2018, 8:35 AM
jtrh
jtrh - avatar