提问人:Oliver Vakomies 提问时间:12/4/2015 更新时间:12/4/2015 访问量:307
是什么导致我LNK2019链接器错误?
What is causing me to get the linker error LNK2019?
问:
我正在尝试编写一个程序来计算球在不同时间点的高度,但是每当我尝试编译时,我都会LNK2019出错。此外,它一直告诉我我的双打被转换为整数,但我不知道为什么。
1>------ 构建开始:项目:抛物线,配置:调试 Win32 ------ 1>抛物线.cpp 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola\constants.h(2):警告 C4244:“initializing”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola\Parabola.cpp(20):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola.cpp(21):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola.cpp(22):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola\Parabola.cpp(23):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola.cpp(24):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola\Parabola.cpp(25):警告 C4244:“argument”:从“double”转换为“int”,可能丢失数据 1>功能.cpp 1>C:\Users\Oliver\Documents\Visual Studio 2015\Projects\Parabola\Parabola\constants.h(2):警告 C4244:“initializing”:从“double”转换为“int”,可能丢失数据 1> 生成代码... 1>Parabola.obj:错误 LNK2019:函数 _main 中引用的未解析的外部符号“double __cdecl ballHeight(int,double)”(?ballHeight@@YANHN@Z) 1>C:\Users\OLIVER\Documents\Visual Studio 2015\Projects\Parabola\Debug\Parabola.exe:致命错误LNK1120:1 个未解决的外部问题 ========== 构建:0 次成功,1 次失败,0 次最新,0 次跳过 ==========
这是所有文件。
主要
#include "stdafx.h"
#include <iostream>
#include "FUNCTIONS.h"
#include "CONSTANTS.h"
int main()
{
using namespace std;
cout << "Enter the height of a building (in metres) you wish to simulate dropping a ball off of." << endl;
double bHeight = getHeight(); //Building height is defined
ballHeight(bHeight, 0); //Calls the function ballHeight at various points in time
ballHeight(bHeight, 1);
ballHeight(bHeight, 2);
ballHeight(bHeight, 3);
ballHeight(bHeight, 4);
ballHeight(bHeight, 5);
return 0;
}
功能
#include "stdafx.h"
#include <iostream>
#include "CONSTANTS.h"
#include "FUNCTIONS.h"
double getHeight()
{
using namespace std;
double x = 0;
cin >> x;
return x;
}
double ballHeight(double bHeight, int seconds)
{
using namespace std;
double currentHeight = bHeight - gConstant * seconds * seconds / 2; //Calculates current ball height.
cout << "At " << seconds << " seconds, the ball is at height: " << currentHeight << " metres." << endl; //Returns the ball height.
return 0;
}
函数.h
#pragma once
#include "stdafx.h"
int main();
double getHeight();
double ballHeight(int seconds, double bHeight);
void tryAgain();
常量.h
#pragma once
const int gConstant = 9.8;
答:
double ballHeight(double bHeight, int seconds)
与。
double ballHeight(int seconds, double bHeight)
签名不同。
评论