找不到标识符

编程入门 行业动态 更新时间:2024-10-23 11:26:56
本文介绍了找不到标识符-Noob C ++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚开始学习C ++,我来自C#.下面是一些我试图计算重载方法的代码,但出现错误找不到标识符"?请保持温柔:

I have just started learning C++, I come from a C# background. Below is some code where I am trying to cal an overloaded method, but I get the error "identifier not found"? Please be gentle:

#include "stdafx.h" #include <iostream> using namespace std; int _tmain() { char input = ''0''; while(input != ''d'' && input != ''g'') { cout << "Please select a company to recieve a quote from\nDHL - (d)\nGlobalMail - (g)\n\n(select either g or d)->"; cin >> input; } cout << "\n\n"; switch (input) { case ''d'': break; case ''g'': cout << "GlobalMail, great choice! Please enter the weight of your parcel\n->"; int weight = NULL; cin >> weight; weight = calcPostage(weight); //this line breaks cout << "Your package will cost R" << weight; break; } return 0; } int calcPostage(int weight) { return weight * 108; } int calcPostage(int length, int width, int height) { return (length * width * height) / 5000; }</iostream>

推荐答案

您需要在main之前提到重载calcPostage函数的函数原型,这将解决问题. You need to mention the function prototype for overloaded calcPostage functions before main,that will solve the issue.

编译器从源文件的顶部到底部开始工作. 函数原型是对将要存在的函数的定义,因此编译器知道不会使代码编译失败. 如果发现尚未定义的功能,它将失败,以同样的方式,如果定义了两次,则将失败. 正如Harish所说的那样: int calcPostage(int); int calcPostage(int,int,int); 在main将要修复代码之前,以便编译器知道这些功能将在代码的将来存在. The compiler works from the top of a source file to the bottom. A function prototype is a definition of the function that will exist and so the compiler knows not to fail the code compile. If it finds a function that is not defined already it will fail, in the same way it will fail if a function is defined twice. As Harish has said putting: int calcPostage(int); int calcPostage(int,int,int); before the main will fix the code so that the compiler knows that these function will exist at some point in the future in the code.

更多推荐

找不到标识符

本文发布于:2023-10-07 15:26:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   找不到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!