Cannot convert Class::object

Hi folks.

I've (hopefully) created a vector of objects (Trolls in a rougelike). Each object should have an x and y coordinate set.

I'm attempting to see if I've actually populated the vector correctly and I can get the correct size of the vector but when I try to return the coords for individual objects within the array I get the following error:

1
2
3
4
C:\...\PlayGame.cpp||In member function 'void PlayGame::checkTrolls(std::vector<Troll>)':|
C:\...\PlayGame.cpp|63|error: cannot convert 'Troll::getTrollX' from type 'int (Troll::)()' to type 'int'|
C:\...\PlayGame.cpp|64|error: cannot convert 'Troll::getTrollY' from type 'int (Troll::)()' to type 'int'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


PlayGame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef PLAYGAME_H
#define PLAYGAME_H

#include <string>
#include <vector>

#include "Level.h"
#include "Troll.h"

class Troll;

class PlayGame
{
    public:
        PlayGame();
        void checkTrolls(std::vector<Troll> trollVector);

    private:
        std::vector<Troll> trollVector;
};

#endif // PLAYGAME_H


PlayGame.cpp
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
#include <iostream>
#include <cstdlib>

#include "PlayGame.h"
#include "Player.h"

using namespace std;

PlayGame::PlayGame() {
}

void PlayGame::findTrollInLevel(Level newLevel) {

    char gotCharacter;

    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 70; j++) {
            gotCharacter = newLevel.getSquareContents(j, i);
            if (gotCharacter == 'T') {
                Troll newTroll;
                newTroll.setTrollXY(j, i);
                trollVector.push_back(newTroll);
            }
        }
    }
}

void PlayGame::checkTrolls(vector <Troll> trollVector) {

    int currentTrollX;
    int currentTrollY;

    int trollVectorSize = trollVector.size();
    cout << "Size of Vector: " << trollVectorSize << endl;

    for( int i = 0; i < trollVectorSize; i++) {
        Troll thisTroll = trollVector[i];
        currentTrollX = thisTroll.getTrollX;
        currentTrollY = thisTroll.getTrollY;
        cout << "Troll: " << i << " X: " << currentTrollX << " Y: " << currentTrollY << endl;
    }
}


Troll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef TROLL_H
#define TROLL_H

#include <vector>

#include "Level.h"
#include "PlayGame.h"

class Troll
{
    public:
        Troll();

        int getTrollX();
        int getTrollY();
        void setTrollXY(int x, int y);

    private:
        int _trollX, _trollY;

};

#endif // TROLL_H 


Troll.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "Troll.h"

Troll::Troll() {
}

int Troll::getTrollX() {

    return _trollX;
}

int Troll::getTrollY() {

    return _trollY;
}

void Troll::setTrollXY(int x, int y) {

    _trollX = x;
    _trollY = y;
}


Sorry for the sprawl. Any help would be much appreciated.

Also, does anyone know why the fprum preview button shows no text apart from the username and date at the top? I use the Chrome browser and I've disabled pop up blocking for this domain.
Last edited on
currentTrollX = thisTroll.getTrollX;
thisTroll.getTrollX;is a function pointer. You need to call function using braces ()
braces ()


*parenthesis ;P


yes, I know parenthesis are a type of brace, but calling them braces is confusing, IMO
Actually, braces are the things the dentist gives you when you got some problem with your teeth - http://mexicodental.co/sites/turkeydental.co/files/images/metal-brances_0.jpg

While () is called paremthesis. They are a type of brackets, not braces.

Edit: After reading the brackets wiki. Apparently these { } are called braces, or as I and a lot of other people call them, curly brackets.
Last edited on
Works perfectly, cheers guys!
Topic archived. No new replies allowed.