我几乎没有开始一个新项目,由于这个错误,我无法简单地打印一批结构数据。代码如下:
头文件:
#ifndef EuropeanOption_HPP
#define EuropeanOption_HPP
#include <iostream>
#include <string>
using namespace std;
struct EquityParms
{
double T; // years until expiry
double K; // strike price
double sig; // vol
double r; // risk free rate
double S; // current equity price
};
class EuropeanOption
{
private:
void init(const struct EquityParms data); // initialize EquityParms
public:
};
#ifndef EUROPEANOPTION_CPP
#include "EuropeanOption.cpp"
#endif
#endif
源文件:
#ifndef EUROPEANOPTION_CPP
#define EUROPEANOPTION_CPP
#include "EuropeanOption_H.hpp"
void EuropeanOption::init(const struct EquityParms data)
{
cout << "Years until expiry: \t" << data.T << endl;
cout << "Strike price: \t" << data.K << endl;
cout << "Volatility: \t" << data.sig << endl;
cout << "Risk-free rate: \t" << data.r << endl;
cout << "Current equity price: \t" << data.S << endl;
}
#endif
测试文件:
#include "EuropeanOption_H.hpp"
int main()
{
struct EquityParms batch1 = {0.25, 65, 0.30, 0.08, 60};
struct EquityParms batch2 = {1, 100, 0.2, 0.0, 100};
struct EquityParms batch3 = {1, 10, 0.5, 0.12, 5};
struct EquityParms batch4 = {30, 100, 0.30, 0.08, 100};
init(batch1); // error on this line, "identifier init is undefined"
return 0;
}
如果我尝试构建,编译器错误是:“test.cpp(22): error C3861: 'init': identifier not found”
这实际上是我代码的 100%。我的#include 在那里。我尝试简单地将其命名为更独特的名称,但无济于事。我不明白...你能看看我的错误是什么吗?
谢谢!