Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating a texted based adventure game c++
Here is the code:
C++
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <random>
#include <ctime>
#include <ctype.h>
#include "bits/stdc++.h"

using namespace std;

class Player {

    public:
        int d6_1;
        int d6_2;
        int d6_3;
        int d6_4;
        int d6_5;
        int d6_6;
        double pi = 2 * acos(0.0);
        string playerClass;
        string name;
        string race;
        int strength = 10;
        int dexterity = 10;
        int constituion = 10;
        int intelligence = 10;
        int wisdom = 10;
        int charisma = 10;
        string meleeWeapon = "fists";
        string rangedWeapon;
        string magic;
        
        void statAssign() {
            for (int i = 0; i < 7; i++) {
                srand(time(NULL));
                int d6 = (rand()/pi);
                switch(i) {
                    case 1:
                        d6 = d6_1;
                        cout << abs(d6_1%6+1) << "\n";
                        d6=0;
                        break;
                    case 2:
                        d6 = d6_2;
                        cout << abs(d6_2%6+1) << "\n";
                        d6=0;
                        break;
                    case 3:
                        d6 = d6_3;
                        cout << abs(d6_3%6+1) << "\n";
                        d6=0;
                        break;
                    case 4:
                        d6 = d6_4;
                        cout << abs(d6_4%6+1) << "\n";
                        d6=0;
                        break;
                    case 5:
                        d6 = d6_5;
                        cout << abs(d6_5%6+1) << "\n";
                        d6=0;
                        break;
                    case 6:
                        d6 = d6_6;
                        cout << abs(d6_6%6+1) << "\n";
                        d6=0;
                        break;
                }
        }
    }
};

int main() {
    Player player1;
    player1.statAssign;
    cout << "Type everything in lowercase" << "\n";
    cout << "What is your name, traveler?" << "\n";
    bool nameRestart = true;
    while (nameRestart == true) {
        nameRestart = false;
        cout << "> ";
        cin >> player1.name;
        cout << player1.name << "? Are you sure that's your true name?" << "\n";
        string nameCheck;
        cin >> nameCheck;
        if (nameCheck == "no") {
            nameRestart = true;
        } else {
            break;
        }
    }
    cout << "Where do you hail from " << player1.name << "?" << "\n";
    cout << "The Human Cities? Perhaps the Elven Forests? or the Mightly Dwarven Kingdoms?" << "\n";
    string raceChoice;
    cin >> raceChoice;
    /*
    switch(raceChoice) {
        case human:
            player1.race = "human";
            player1.strength++;
            player1.constituion++;
            player1.charisma++;
            
    }
    */

}


This seems fine in my eyes but once ran it comes up with this error:
C++
main.cpp: In member function ‘void Player::statAssign()’:
main.cpp:38:21: warning: variable ‘d6’ set but not used [-Wunused-but-set-variable]
   38 |                 int d6 = (rand()/pi);
      |                     ^~
main.cpp: In function ‘int main()’:
main.cpp:77:13: error: invalid use of non-static member function ‘void Player::statAssign()’
   77 |     player1.statAssign;
      |     ~~~~~~~~^~~~~~~~~~
main.cpp:35:14: note: declared here
   35 |         void statAssign() {
      |              ^~~~~~~~~~
make: *** [<builtin>: main.o] Error 1


If anyone can help with this, please and thank you!

What I have tried:

Scowering google and documentation.
Posted
Updated 31-Jan-23 8:22am

1 solution

When calling a member function you need to use the function call syntax ()
e.g.
C++
player1.statAssign();


clang provides a more helpful diagnostic:
main.cpp:77:13: error: reference to non-static member function must be called; did you mean to call it with no arguments?
    player1.statAssign;
    ~~~~~~~~^~~~~~~~~~
 
Share this answer
 
v3
Comments
Brennon Nevels 31-Jan-23 14:26pm    
This was definitely a facepalm moment
k5054 31-Jan-23 14:28pm    
Yes, and we've all done it, or something similar.
CPallini 31-Jan-23 15:52pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900