如何修复此"argument of type incompatible with parameter"错误?
How do I fix this "argument of type incompatible with parameter" error?
C++的新手,我为"学位"创建了一个枚举,其中包含 3 种类型"安全、网络、软件",当子类尝试使用枚举时会返回类型错误。它专门寻找什么类型?
//Network Student Subclass
#include <string>
#include "degree.h"
#include "student.h"
class NetworkStudent : public Student //This class derives from Student
{
public:
NetworkStudent();
NetworkStudent(
string student_id,
string first_name,
string last_name,
string email,
double age,
double* days,
degree type
);
degree getdegree();
void setdegree(degree d);
void print();
~NetworkStudent();
};
//Enum with 3 Types
#include <string>
//The three types of degrees available
enum degree {SECURITY,NETWORKING,SOFTWARE};
static const std::string degreeTypeStrings[] = { "SECURITY","NETWORKING", "SOFTWARE" };
//Network Student definition with invalid type error for NETWORKING
#include "student.h"
#include "networkStudent.h"
using std::cout;
NetworkStudent::NetworkStudent()
{
//Right here is where I get the error on NETWORKING
setdegree(NETWORKING);
}
错误状态:"度"类型的参数与"度"类型的参数不兼容。我认为学位是一个枚举,网络也是一个枚举。
正如评论中的其他人所提到的,您在这里寻找的内容实际上是degree::NETWORKING
.原因是NETWORKING
是枚举degree
的一部分,而不是在全局空间中。因此,您需要指定要使用的NETWORKING
。
相关文章:
- Problems with std::cin.fail()
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- Boost.TEST with CLion: "Test framework quit unexpectedly"
- 避免碎片化的ClientHellos with OpenSSL (DTLS)
- Issues with Win32 ReadProcessMemory API
- Qt with WinAPI MouseProc
- [[maybe_unused]] with structured_binding?
- Issue with WriteProcessMemory
- OpenCV RTP-Stream with FFMPEG
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- std::adjacent_difference with std::chrono time_point
- 修复"-Wunused-parameter"取决于预处理器条件的警告
- C++模板错误:"invalid explicitly-specified argument for template parameter"
- DLL Made with CMake 使程序崩溃
- QtCreator with C 库中的链接器问题
- 在 lambda(parameter) 中为 std::transform with std::sregex_token
- 如何修复此"argument of type incompatible with parameter"错误?
- 谷歌模拟 - 怎么说"function must be called ONCE with a certain parameter but ok to be called many times with
- 使用可变参数模板实现 Get (元组) 得到"parameter packs not expanded with ‘...’"错误