Object refernce in function parameters problem

Hello!
I was in the course of making a game and one of the functions requires a reference to a map object. When I try to build and run the program, however, it shows the error message, "error: passing 'const MapFunctions' as 'this' argument of 'int MapFunctions::whatEverFunction()' discards qualifiers [-fpermissive]" (the reason for 'whatEverFunction()' being used in the quote is that there is 17 error messages all the same except the part that says 'whatEverFunction()').
Here is the code:

Player.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef PLAYER_H_INCLUDED
#define PLAYER_H_INCLUDED

#define North 0
#define East 1
#define South 2
#define West 3

#include "LivingObject.h"

using namespace std;

class Player: public LivingObject
{
public:
    Player(){
    exp = 0;
    }
    void incExp(int a)
    {
        exp += a;
    }
    int getExp(){
    return exp;}
    void DirectionCheck(const MapFunctions& MapObject)
{
    bool DirectionSpecifier[4];
    int DirectionSpecifierCount = 0;
    if(locy<MapObject.getRows())
    {
        if(MapObject.ReadMap(locx,locy+1)!=0)
        {
            DirectionSpecifier[North]=1;
            DirectionSpecifierCount++;
        }
    }
    else
    {
        DirectionSpecifier[North]=0;
    }
    if(locx<MapObject.getCols())
    {
        if(MapObject.ReadMap(locx+1,locy)!=0)
        {
            DirectionSpecifier[East]=1;
            DirectionSpecifierCount++;
        }
    }
    else
    {
        DirectionSpecifier[East]=0;
    }
    if(locy>0)
    {
        if(MapObject.ReadMap(locx,locy-1)!=0)
        {
            DirectionSpecifier[South]=1;
            DirectionSpecifierCount++;
        }
    }
    else
    {
        DirectionSpecifier[South]=0;
    }
    if(locx>0)
    {
        if(MapObject.ReadMap(locx-1,locy)!=0)
        {
            DirectionSpecifier[West]=1;
            DirectionSpecifierCount++;
        }
    }
    else
    {
        DirectionSpecifier[West]=0;
    }
    for(int i=0; i<4; i++)
    {
        if(DirectionSpecifier[i]!=0 && DirectionSpecifierCount>2)
        {
            switch(i)
            {
            case 0:
                cout << "north, ";
                break;
            case 1:
                cout << "east, ";
                break;
            case 2:
                cout << "south, ";
                break;
            case 3:
                cout << "west, ";
                break;
            }
            DirectionSpecifierCount--;
        }
        else if(DirectionSpecifier[i]!=0 && DirectionSpecifierCount>1)
        {
            switch(i)
            {
            case 0:
                cout << "north and ";
                break;
            case 1:
                cout << "east and ";
                break;
            case 2:
                cout << "south and ";
                break;
            case 3:
                cout << "west and ";
                break;
            }
            DirectionSpecifierCount--;
        }
        else if(DirectionSpecifierCount=1 && DirectionSpecifier[i]!=0)
        {
            switch(i)
            {
            case 0:
                cout << "north.";
                break;
            case 1:
                cout << "east.";
                break;
            case 2:
                cout << "south.";
                break;
            case 3:
                cout << "west.";
                break;
            }
            DirectionSpecifierCount--;
        }
    }
}
//Finds the start of the map and puts the player there.
       void FindStart(const MapFunctions& MapObject)
{
    for(int lyx = 0; lyx<MapObject.getRows(); lyx++)
    {
        for(int lxy = 0; lxy<MapObject.getCols(); lxy++)
        {
            if(MapObject.ReadMap(lyx,lxy) == 2)
            {
                locx = lyx;
                locy = lxy;
                MapObject.WriteMap(lyx,lxy,1);
            }
        }
    }
}
protected:
    int exp, locx, locy;
    bool IgnoreSpecifier;
};

#endif // PLAYER_H_INCLUDED 


MapFunctions.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef MAPFUNCTIONS_H_INCLUDED
#define MAPFUNCTIONS_H_INCLUDED

#include <iostream>
#include <cstdlib>
#include <new>
#include <string>
#include <sstream>
#include <fstream>

using namespace std;

class MapFunctions
{
public:
    MapFunctions();
    void MapRead(); // Get a map from a file.
    int ReadMap(int xvalue, int yvalue); // Read one part of the map.
    void WriteMap(int xvalue, int yvalue, int writevalue); // Write a new value to one part of the map.
    void MapDelete();
    int getLevel();
    int getRows();
    int getCols();
    void setLevel();
    ~MapFunctions();
protected:
    int level;
private:
    int ** Map;
    int rows, cols, StartTextSize;
    string StartText;
};

#endif // MAPFUNCTIONS_H_INCLUDED 


This post is carried on over a second post, due to the lack of space.

Enemy.cpp (implementation file of Enemy.h):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Enemy.h"

void Enemy::setStats(int a, int b, int c, int d, int e, int f, int g, const MapFunctions& MapObject)
{
    atk = a+(MapObject.getLevel()/enemyAttackModifier);
    def = b+(MapObject.getLevel()/enemyDefenceModifier);
    mag = c+(MapObject.getLevel()/enemyMagicModifier);
    heal = d+(MapObject.getLevel()/enemyHealthModifier);
    maxheal = e+(MapObject.getLevel()/enemyMaximumHealthModifier);
    mon = f+(MapObject.getLevel()/enemyMoneyModifier);
    speed = g+(MapObject.getLevel()/enemyMoneyModifier);
}

void Goblin::attack()
{
    cout << "'Glab ook agkh!' The Goblin stabs you with his dagger.";
}

void Orc::attack()
{
    cout << "'Orc smash!' The orc attempts to crush you with his club.";
}

void Bat::attack()
{
    cout << "The bat bites you. Ouch!";
}
void Spirit::attack()
{
    cout << "The spirit turns purple and you feel weaker. The spirit then becomes almost clear again.";
}
void Skeleton::attack()
{
    cout << "The skelenton uses his best attack: 'The boner'!";
}
void DarkKnight::attack()
{
    cout << "The dark knight lunges his sword through your chest.";
}
void CarnivorousHorse::attack()
{
    cout << "'Neigh, Whinny'... the horse kicks you in the face. He will only eat you when you're dead.";
}
void STDMonster::attack()
{
    cout << "Removes your clothes and gives you a 'good time' (until you realise that this was purposely done to give you syphilis).";
}
void InsectSwarm::attack()
{
    cout << "The swarm of insects bite and sting you. Ouch! You are now red.";
}
void Dog::attack()
{
    cout << "'Woof, woof! Grrrr!' The dog bites you!";
}
void MrGappube::attack()
{
    cout << "As he is wearing his special glasses that make you look like a constipated penguin, he fucks you so hard that it's untrue. The repetitive banging motion is of such great strength (amazing for a 'man' with a two inch willy when erect), that damage is caused.";
}
void FootballMonster::attack()
{
    cout << "He looks in his porn magazine (We Love Footballers Who Cheat On Their Wife Mag) and masturbates. Some of his jizz lands on you and, as it contains assorted strong acids, you suffer acid burns and other acid related damage.";
}
void DemonStripOGram::attack()
{
    cout << "The demonic strip-o-gram begins to remove it's clothes in front of you. The demon's willy is then revealed and, as it doesn't ever wash 'down below', it reeks terribly. The noxious stench of his smelly willy smells so bad that it causes you to be violently sick, to the extent that internal damage is caused.";
}


Sorry if this is a bit vague. Would anyone be ale to tell me the problem's solution, please?
Thanks for your time!
[/code]

Sorry if this is a bit vague. Would anyone be ale to tell me the problem's solution, please?
Thanks for your time!
If you have a const reference to the object you can't call non-const member functions on it. You try to do this on line 149 in Player.h.

If you want to manipulate the object use a non-const reference.
I had never considered that. Thanks!
Topic archived. No new replies allowed.