具有函数原型的返回值

时间:2018-10-06 01:29:35

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

我遇到的问题是VS(Visual Studio)给我错误C4715'functionadd':必须返回一个值。我了解编译器要告诉我的内容;但是,我不知道如何解决。我只是想让人们更加熟悉函数原型!!!最后,如果有人还可以向我展示如何对结构进行原型制作,那么也将不胜感激。

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;
}

1 个答案:

答案 0 :(得分:2)

您的头文件包含函数的定义,而不是函数原型。摆脱{}字符,并以;终止原型。

#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
相关问题