相关疑难解决方法(0)

C++应该消除头文件吗?

许多语言(如Java,C#)不会将声明与实现分开.C#有一个部分类的概念,但实现和声明仍然保留在同一个文件中.

为什么C++没有相同的型号?拥有头文件更实用吗?

我指的是当前和即将推出的C++标准版本.

c++ header-files

70
推荐指数
9
解决办法
1万
查看次数

5
推荐指数
3
解决办法
2461
查看次数

为什么C需要原型函数而Java不需要?

我已经学习了 Java 课程,并正在尝试使用 K&R 自学 C。到目前为止一切顺利,但我不明白原型的目的。请参阅下面代码中的 2 // 注释:

#include <stdio.h>

float convert(int); **//Why is this needed...**

main()
{
    int i;

    for(i = 0; i <= 300; i += 20)
        printf("F: %3d C: %6.1f\n",i,convert(i));

    system("Pause");
    return 0;
}

float convert(int f) **//When we already have this?**
{
    float c = (5.0/9.0) * (f-32.0);
    return c;
}
Run Code Online (Sandbox Code Playgroud)

在 Java 中,您可以声明类似的函数public static float convert(int f),但根本不需要原型。这对我来说似乎简单得多。为什么有区别?

c java prototype function

4
推荐指数
1
解决办法
5069
查看次数

未明确引用'(我的所有功能)'

我收到所有这些错误:

未定义引用'getLength()'
未定义引用'getWidth()'
未定义引用'getArea(double,double)'
未定义引用'displayData(double,double,double)'

这是我的代码:

#include <iostream>

using namespace std;

double getLength();
double getWidth();
double getArea(double,double);
void displayData(double,double,double);

int main()
{
    double length;
    double width;
    double area;

    length = getLength();
    width = getWidth();
    area = getArea(length,width);
    displayData(length,width,area);

    return 0;
}

//getLength function
double getLength();
{

    double length;
    cout << "Length: ";
    cin >> length;

    return length;

}

//getWidth function
double getWidth();
{
    double width;
    cout << "Width: ";
    cin >> width;

    return width;
}

//GetArea function
double getArea(double lenght, …
Run Code Online (Sandbox Code Playgroud)

c++

-2
推荐指数
1
解决办法
165
查看次数

标签 统计

c++ ×3

c ×1

declaration ×1

function ×1

header-files ×1

java ×1

prototype ×1