我一直在使用这个模板来制作我的类来存储程序各个部分的数据。
//Classs that DOES NOT work
//"MiningPars.h"
#pragma once
#ifndef MININGPAR_H
#define MININGPAR_H
#include <iostream>
#include <fstream>
using namespace std;
class MiningPars
{
public:
int NumYears;
double iRate;
int MaxMineCap;
int MaxMillCap;
int SinkRate;
double ReclaimCost;
double PitSlope;
public:
MiningPars();
MiningPars(int numYears,double irate,int maxMineCap,int maxMillCap,
int sinkRate, double reclaimCost, double pitSlope): NumYears(numYears),
iRate(irate),MaxMineCap(maxMineCap),MaxMillCap(maxMillCap),SinkRate(sinkRate),
ReclaimCost(reclaimCost),PitSlope(pitSlope) {}
};
#endif
当我刚刚宣布一个新的采矿标准时,它给了我错误
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall MiningPars::MiningPars(void)" (??0MiningPars@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'par''(void)" (??__Epar@@YAXXZ)
即我的代码如下所示:
#include "MiningPars.h"
MiningPars par;//Error
vector <PredecessorBlock> PREDS;//is okay
void main()
{
par.iRate = .015;
//... etc.
}
大多数 MSDN 和其他谷歌搜索都说我没有正确声明事物或者我没有添加适当的依赖项,但它与我创建另一个类的格式相同。我的其他工作的一个例子可以在这里看到:
//Classs that works
#pragma once
#ifndef PREDECESSOR_H
#define PREDECESSOR_H
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class PredecessorBlock
{
public:
int BLOCKID;
vector <int> PREDS_IDS;
int PredCount;
public:
PredecessorBlock();
PredecessorBlock(int blockID,vector<int>predsids,
int predcount) : BLOCKID(blockID),
PREDS_IDS(predsids), PredCount(predcount)
{}
};
#endif
所以这让我很困惑。感谢您提供的任何建议