【问题标题】:Return Value with Function Prototype [duplicate]带有函数原型的返回值
【发布时间】:2018-10-06 01:29:35
【问题描述】:

我遇到的问题是 VS (visual studio) 给了我错误 C4715 'functionadd': must return a value。我明白编译器试图告诉我什么;但是,我不知道如何解决它。我只是想更熟悉函数原型!最后,如果有人也可以向我展示如何制作该结构的原型,我将不胜感激。

Main.cpp

#include "pch.h"
#include <iostream>
#include <string>
#include "func.h"



enum class myenum {
    NUMBERONE,
    NUMBERTWO,
    NUMBERTHREE,
    NUMBERFOUR,
    NUMBERFIVE,
};

struct mystruct{
    int age = 9;
    int willbeage;
    int avg;
    std::string about;
    std::string lastname;
} mystruct1;

int main()


{
    std::cout << "Hello World!\n";
    return 0;
}

func.h

#pragma once
#ifndef FUNC_H
#define FUNC_H
#include "pch.h"
int functionadd(int, int, int) {
}
void functionadd() {
}

int functionadd(int, int, int, int) {
}
#endif

func.cpp

#pragma once
#include "pch.h"
#include <iostream>
int functionadd(int a, int b, int c) {
    return a + b + c;
}
void functionadd() {
    std::cout << "Hello";
}

int functionadd(int a, int b, int c, int d) {
    return a + b + c + d;
}

【问题讨论】:

标签: c++ return-value function-prototypes


【解决方案1】:

您的头文件包含函数的定义,而不是函数原型。去掉{} 字符并使用; 终止您的原型。

#pragma once
#ifndef FUNC_H
#define FUNC_H
#include "pch.h"
int functionadd(int, int, int);
void functionadd();
int functionadd(int, int, int, int);
#endif

【讨论】:

  • 天哪,这么简单的错误。非常感谢!
  • 不客气。不要忘记接受我的回答,这样其他人就不会在这里绊倒发现它已经回答了。
  • Ty 提醒
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 2011-01-20
  • 2023-02-06
  • 1970-01-01
  • 1970-01-01
  • 2012-04-04
相关资源
最近更新 更多