【发布时间】:2018-02-01 17:14:33
【问题描述】:
我正在尝试使用此页面了解人工神经网络(它在处理中,但我在更改一些小部分时将其转换为 C++):http://natureofcode.com/book/chapter-10-neural-networks/ 但是当我在下面运行代码时,我得到了这个错误:
main.cpp: In function ‘int main()’:
main.cpp:36:7: error: request for member ‘feedforward’ in ‘idk’, which is of non-class type ‘Perceptron()’
idk->feedforward({1.0, .5});
我环顾四周,但我认为我找不到在调用方法时遇到此错误的人。 代码:
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <vector>
const double e = 2.71828182845904523536;
float S(float in){
return 1 / (1 + pow(e, -(in)));
}
double fRand(double fMin, double fMax){
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
struct Perceptron{
Perceptron(int n);
std::vector<double> weights;
int feedforward(float inputs[]);
};
Perceptron::Perceptron (int n){
weights.assign(n, fRand(-1.0, 1.0));
}
int Perceptron::feedforward(float inputs[]){
return 0; // I have this just for testing that I can call it
}
int main(){
srand(time(NULL));
Perceptron idk();
idk.feedforward({1.0, .5});
return 0;
}
【问题讨论】:
-
最头疼的解析又来了! :P
-
@Rakete1111 如果其中有更深层次的智慧,那是我无法理解的。你能详细说明一下吗?
-
行
Perceptron idk();不是一个名为idk的对象的声明;它是不带参数并返回Perceptron的函数的函数原型。删除括号以解决此问题。 -
不要破坏你自己的帖子来删除错误的来源。它使问题难以理解。
标签: c++ function methods struct