gpt4 book ai didi

c++ - 是什么导致我收到链接器错误 LNK2019?

转载 作者:行者123 更新时间:2023-11-28 05:56:28 26 4
gpt4 key购买 nike

我正在尝试编写一个程序来计算球在不同时间点的高度,但每当我尝试编译时,我都会收到错误 LNK2019。此外,它一直告诉我我的 double 已转换为整数,但我不知道为什么。

1>------ Build started: Project: Parabola, Configuration: Debug Win32 ------ 1> Parabola.cpp 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\constants.h(2): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(20): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(21): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(22): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(23): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(24): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(25): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1> Functions.cpp 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\constants.h(2): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data 1> Generating Code... 1>Parabola.obj : error LNK2019: unresolved external symbol "double __cdecl ballHeight(int,double)" (?ballHeight@@YANHN@Z) referenced in function _main 1>C:\Users\OLIVER\Documents\Visual Studio 2015\Projects\Parabola\Debug\Parabola.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这是所有的文件。

主要

#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)

签名不同。

关于c++ - 是什么导致我收到链接器错误 LNK2019?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com