/home/ubuntu/Main.cpp:9:29: error: ISO C++ forbids declaration of ‘item’ with no type [-fpermissive] 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^/home/ubuntu/Main.cpp: In member function ‘int Item::item(std::string, int)’:/home/ubuntu/Main.cpp:9:33: error: only constructors take member initializers 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^~~~~~/home/ubuntu/Main.cpp:9:62: warning: no return statement in function returning non-void [-Wreturn-type] 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^/home/ubuntu/Main.cpp: In constructor ‘book::book(std::string, int)’:/home/ubuntu/Main.cpp:15:44: error: no matching function for call to ‘Item::Item(std::string&, int&)’ 15 | book(string id,int days) : Item(id,days) {} | ^/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item()’ 3 | class Item | ^~~~/home/ubuntu/Main.cpp:3:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(const Item&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(Item&&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp: At global scope:/home/ubuntu/Main.cpp:24:15: error: expected ‘)’ before ‘id’ 24 | dvd(String id,int days) : Item(id,days){} | ~ ^~~ | )/home/ubuntu/Main.cpp: In constructor ‘magazine::magazine(std::string, int)’:/home/ubuntu/Main.cpp:33:46: error: no matching function for call to ‘Item::Item(std::string&, int&)’ 33 | magazine(string id,int days):Item(id,days){} | ^/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item()’ 3 | class Item | ^~~~/home/ubuntu/Main.cpp:3:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(const Item&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(Item&&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:46:25: error: no matching function for call to ‘dvd::dvd(std::string&, int&)’ 46 | dvd d(id,daysoverdue); | ^/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd()’ 21 | class dvd : public Item | ^~~/home/ubuntu/Main.cpp:21:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(const dvd&)’/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(dvd&&)’/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:49:23: error: ‘m’ was not declared in this scope 49 | d.calculatefees()+m.calculatefees(); | ^
Question
/home/ubuntu/Main.cpp:9:29: error: ISO C++ forbids declaration of ‘item’ with no type [-fpermissive] 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^/home/ubuntu/Main.cpp: In member function ‘int Item::item(std::string, int)’:/home/ubuntu/Main.cpp:9:33: error: only constructors take member initializers 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^~ | )/home/ubuntu/Main.cpp: In constructor ‘magazine::magazine(std::string, int)’:/home/ubuntu/Main.cpp:33:46: error: no matching function for call to ‘Item::Item(std::string&, int&)’ 33 | magazine(string id,int days):Item(id,days){} | ^/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item()’ 3 | class Item | ^~/home/ubuntu/Main.cpp:9:62: warning: no return statement in function returning non-void [-Wreturn-type] 9 | item(string id,int days) : itemid(id),daysoverdue(days){} | ^/home/ubuntu/Main.cpp: In constructor ‘book::book(std::string, int)’:/home/ubuntu/Main.cpp:15:44: error: no matching function for call to ‘Item::Item(std::string&, int&)’ 15 | book(string id,int days) : Item(id,days) {} | ^/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item()’ 3 | class Item | ^~/home/ubuntu/Main.cpp:3:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(const Item&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(Item&&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp: At global scope:/home/ubuntu/Main.cpp:24:15: error: expected ‘)’ before ‘id’ 24 | dvd(String id,int days) : Item(id,days){} | ~ ^/home/ubuntu/Main.cpp:3:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(const Item&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:3:7: note: candidate: ‘Item::Item(Item&&)’/home/ubuntu/Main.cpp:3:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:46:25: error: no matching function for call to ‘dvd::dvd(std::string&, int&)’ 46 | dvd d(id,daysoverdue); | ^/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd()’ 21 | class dvd : public Item | ^/home/ubuntu/Main.cpp:21:7: note: candidate expects 0 arguments, 2 provided/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(const dvd&)’/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(dvd&&)’/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:49:23: error: ‘m’ was not declared in this scope 49 | d.calculatefees()+m.calculatefees(); | ^
Solution
The error messages you're seeing are due to a few issues in your C++ code:
-
The function
itemis declared without a return type. In C++, every function must have a return type. If you don't want to return anything, you should usevoid. However, from the context, it seems likeitemis supposed to be a constructor for a classItem. Constructors in C++ should have the same name as the class, so you should renameitemtoItem. -
The
Itemclass doesn't have a constructor that takes two arguments (string id, int days). You need to declare and define this constructor in theItemclass. -
The
dvdclass is declared with a constructor that takes aString(with a capital S) as an argument. C++ is case-sensitive, soStringandstringare not the same. You should changeStringtostring. -
The
dvdandmagazineclasses are trying to call a two-argument constructor of theItemclass, but it doesn't exist. As mentioned above, you need to add this constructor to theItemclass. -
In the
mainfunction, you're trying to create an instance of thedvdclass with two arguments, but this constructor doesn't exist. You need to add it to thedvdclass. -
Also in the
mainfunction, you're trying to use a variablemthat hasn't been declared. You need to declarembefore you can use it.
I hope this helps! Let me know if you have any other questions.
Similar Questions
/home/ubuntu/Main.cpp:24:15: error: expected ‘)’ before ‘id’ 24 | dvd(String id,int days) : Item(id,days){} | ~ ^~~ | )/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:46:17: error: no matching function for call to ‘dvd::dvd(std::string&, int&)’ 46 | dvd d(did,dd); | ^/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(const dvd&)’ 21 | class dvd : public Item | ^~~/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:21:7: note: candidate: ‘dvd::dvd(dvd&&)’/home/ubuntu/Main.cpp:21:7: note: candidate expects 1 argument, 2 provided/home/ubuntu/Main.cpp:49:23: error: ‘m’ was not declared in this scope 49 | d.calculatefees()+m.calculatefees(); | ^
sol.cpp: In function ‘int main()’:sol.cpp:8:83: error: ‘std::string’ {aka ‘class std::__cxx11::basic_string<char>’} has no member named ‘kength’; did you mean ‘length’? 8 | cout<<one<<" "<<two<<" "<<three<<" "<<" - "<<(one.length()+two.length()+three.kength())<<endl; | ^~~~~~ | length
/home/ubuntu/Main.cpp:22:5: error: expected unqualified-id before ‘delete’ 22 | int delete(){ | ^~~~~~/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:72:13: error: ‘insert’ was not declared in this scope 72 | insert(item); | ^~~~~~/home/ubuntu/Main.cpp:75:63: error: expected primary-expression before ‘)’ token 75 | printf("Element deleted from queue is :%d",delete()); | ^
/home/ubuntu/Main.cpp:3:15: error: expected unqualified-id before ‘int’ 3 | char register(int weight, double height) { | ^~~/home/ubuntu/Main.cpp:3:15: error: expected ‘)’ before ‘int’ 3 | char register(int weight, double height) { | ~^~~ | )/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:30:16: error: expected primary-expression before ‘register’ 30 | category = register(weight, height); | ^~~~~~~~
Identify the issue in this C++ code snippet:class Car {public:int speed;void Car() { speed = 0; }};a.Missing data encapsulationb.Incorrect class constructor syntaxc.No errord.Inheritance misuse
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.