在使用 -> 和 * 时,通过迭代器访问类参数和函数都会失败。搜索了很多线程都无济于事。除非添加更多细节,否则它不会让我提交问题,嗯,co 代表连接,并且整天都在仔细检查 const 和指针引用。
剪辑:
vector<Axon>::iterator ait;
ait=axl.begin();
const Neuron* co=ait->get_conn();
饮食编译代码:
#include <iostream>
#include <vector>
using namespace std;
class Neuron;
class Axon;
class Neuron{
friend class Axon;
public:
Neuron(int);
void excite(double);
void connect(const Neuron *);
//void grow_ax();
private:
double _exc;
vector<Axon> axl;
};
class Axon{
friend class Neuron;
public:
Axon();
const Neuron* get_conn();
private:
double cond; //conductivity
const Neuron* connection;
};
Neuron::Neuron(int numax){
_exc=0;
vector<Axon> axl (numax,Axon());
}
Axon::Axon(){
cond=1;
connection=0;
}
void Neuron::connect(const Neuron * nP){
vector<Axon>::iterator ait;
ait=axl.begin();
const Neuron* co=ait->get_conn(); //error is here,
//if (ait->connection==0) these don't work
//ait->connection=nP; <===
}
const Neuron* Axon::get_conn(){
return connection;
}
int main(){
Neuron n1=Neuron(1);
Neuron n2=Neuron(0);
Neuron* n2p=&n2;
n1.connect(n2p);
}
提前致谢