【发布时间】: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;
}
【问题讨论】:
-
原型可能没有主体(甚至不是空的
{ })。相反,将其替换为单个分号 (;)。查看@1201ProgramAlarm 提供的链接,了解如何操作。
标签: c++ return-value function-prototypes