Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Am I using void functions incorrectly?

Tags:

c++

function

void

Errors:

  • C2182: 'tellStats' : illegal use of type 'void'
  • C2440: 'initializing' : cannot convert from 'std::string' to 'int'
  • incomplete type is not allowed.

All of these errors are found on this line:

    //ClassPractice.cpp
    void tellStats(pick);

which calls...

    //Functions.h
    void tellStats(string);

which is defined as...

    //Functions.cpp
        void tellStats(string choice)
    {
        if (choice == "wizard")
            {
            cout << "These are the Wizard's stats:" << endl;
            cout << "Max HP: 80\nSpeed: 7\nAttack: 10" << endl;
            }
    }

I don't understand why I am getting these errors. I don't know why an int is even involved with the error. I see nothing referring to ints in these sections of code. I thought I was using 'void' correctly because I don't want to return a value with the function.

like image 526
BrandonFlynn-NB Avatar asked Feb 11 '26 03:02

BrandonFlynn-NB


1 Answers

You dont call a function with the return type. Dont say:

void tellStats(pick);

just use tellStats(pick);.

Is that line the only place you call tellStats?

like image 132
marsh Avatar answered Feb 16 '26 19:02

marsh