Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从双指针获取值?_C++_Pointers - Fatal编程技术网

C++ 如何从双指针获取值?

C++ 如何从双指针获取值?,c++,pointers,C++,Pointers,我正在尝试打印以下代码返回的值: Agent** Grid::GetAgent(int x, int y) { return &agents[x][y]; } 它返回一个双指针,然后打印 std::cout << *grid.GetAgent(j, k) << endl; 和Agent.cpp #include "Agent.h" Agent::Agent(void) { m_age = 0; m_fitness = -1; }

我正在尝试打印以下代码返回的值:

Agent** Grid::GetAgent(int x, int y)
{
    return &agents[x][y];
}
它返回一个双指针,然后打印

std::cout << *grid.GetAgent(j, k) << endl;  
和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;
}

你需要定义一个函数
ostream&operator你需要定义一个函数
ostream&operator我正要问同样的问题。。成员“agents”的类型是什么?您需要定义
运算符“double pointer”可能会被误解为“指向double的指针”。你说的是指向指针的指针。我想知道你为什么用指针指向这里的指针?只是一句关于编程风格的评论,你的问题已经被其他人回答了。我正要问同样的问题。。成员“agents”的类型是什么?您需要定义
运算符“double pointer”可能会被误解为“指向double的指针”。你说的是指向指针的指针。我想知道你为什么用指针指向这里的指针?只是关于编程风格的一个评论,你的问题已经被其他人回答了
main.cpp:53: error: no match for ‘operator<<’ in ‘std::cout << * * grid.Grid::GetAgent(j, k)’
#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
#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;
}
ostream& operator<<(ostream& out, const Agent& x)
{
  // your code to print x to out here, e.g.
  out << (int)x.GetType() << ' ' << x.GetFitness() << ' ' << x.GetAge() << '\n';
  return out;
}