Matthew C
Matthew C

Reputation: 91

C++ explicit type is missing('int' assumed)

Hi I have an error in my c++ code. I have 2 .cpp files and 1 .h file, Im trying to access 5 strings and 1 int from the header file but I get an error that says "explicit type is missing('int' assumed).

I have some other errors too which are: Missing type specifier, Shops::Items redefinition; different basic types, Overloaded function differs only by return type and declaration is incompatible.

Here are my files:

UserChoice.h

#include <iostream>
#include <string>

using namespace std;

#ifndef USERCHOICE_H
#define USERCHOICE_H

class Shops
{
public:

    double Items(string, string, string, string, string, int);

    int main()
    {
        std::cout << newItem1;
    }

private:
    string newItem1;
    string newItem2;
    string newItem3;
    string newItem4;
    string newItem5;
    int newItems;

};
#endif

Items.cpp

#include "UserChoice.h"

Shops::Items(string Item1, string Item2, string Item3, string Item4, string Item5, int     Items)
{
    newItem1 = Item1;
    newItem2 = Item2;
    newItem3 = Item3;
    newItem4 = Item4;
    newItem5 = Item5;
    newItems = Items;
}

Source.cpp

#include "UserChoice.h";
#include <string>

int main()
{
    string Item1;
    string Item2;
    string Item3;
    string Item4;
    string Item5;
    int items;

    std::cout << "What what you like? Chicken, Meat, Fish, Carrot or Apple?\n";
    std::cin >> Item1;
    std::cout << "\nAnything else?\n";
    std::cin >> Item2;
    if(Item2 == "nothing else")
    {

    }
    std::cout << "\nAnything else?\n";
    std::cin >> Item3;
    std::cout << "\nAnything else?\n";
    std::cin >> Item4;
    std::cout << "\nAnything else?\n";
    std::cin >> Item5;
    std::cout << "\nAnything else?\n";
}

Error line

Shops::Items(string Item1, string Item2, string Item3, string Item4, string Item5, int Items)

All the code isn't finished yet so I hope you can help me find and fix these errors. Thanks in advance and if you need anymore info just ask me.

Upvotes: 4

Views: 54645

Answers (2)

Daniel Frey
Daniel Frey

Reputation: 56863

You are missing the return type in the definition in Items.cpp:

double Shops::Items(string Item1, string Item2, string Item3, string Item4, string Item5, int Items)
{
    //...
}

You also need to return some value, both for Shops::Items and for the class' main function.

Regarding the naming: It looks weird to have the "normal" main function replicated inside the class and it also looks weird to have a parameter named exactly like the class is named. It does in fact work, but I would flag it in a code review FWIW. :)

Upvotes: 5

Montdidier
Montdidier

Reputation: 1210

You are missing the return type in the implementation file (cpp) for Shops::Items which would be a double on the basis of what you have your in header file. The other errors you have are very likely related.

It is a little disconcerting having a method named main within your class as it's normally a function name used for your program entry point.

Upvotes: 8

Related Questions