我正在尝试打印以下代码返回的值:
Agent** Grid::GetAgent(int x, int y)
{
return &agents[x][y];
}
它返回一个双指针,并打印
std::cout << *grid.GetAgent(j, k) << endl;
给出了一个内存位置,但是当我尝试
std::cout << **grid.GetAgent(j, k) << endl;
我得到错误
main.cpp:53: error: no match for ‘operator<<’ in ‘std::cout << * * grid.Grid::GetAgent(j, k)’
如何打印 *grid.GetAgent(j, k) 中的值?
下面是 Agent.h
#ifndef AGENT_H
#define AGENT_H
enum AgentType { candidateSolution, cupid, reaper, breeder};
class Agent
{
public:
Agent(void);
~Agent(void);
double GetFitness();
int GetAge();
void IncreaseAge();
AgentType GetType();
virtual void RandomizeGenome() = 0;
protected:
double m_fitness;
AgentType m_type;
private:
int m_age;
};
#endif // !AGENT_H
和 Agent.cpp
#include "Agent.h"
Agent::Agent(void)
{
m_age = 0;
m_fitness = -1;
}
Agent::~Agent(void)
{
}
int Agent::GetAge()
{
return m_age;
}
double Agent::GetFitness()
{
return m_fitness;
}
void Agent::IncreaseAge()
{
m_age++;
}
AgentType Agent::GetType()
{
return m_type;
}