c++ - 类向量上的 C++ 编译问题
问题描述
我很难解决编译错误,如下所示。我目前正在研究可能会更改哪些内容以修复错误。谁能告诉我我需要改变什么?我的编译器指出的代码如下。问题也可能在生成文件中,但我不确定要包含什么。非常感谢任何帮助,谢谢!
编译错误:
C:\cygwin64\home\user\cpplab7>nmake -f makefile.ms
Microsoft (R) Program Maintenance Utility Version 14.16.27026.1
Copyright (C) Microsoft Corporation. All rights reserved.
cl /Foms\\main.obj /W4 /WX /Za /EHsc /nologo /c main.cpp
main.cpp
c:\cygwin64\home\user\cpplab7\cs170_vector.h(101): error C2039: 'max': is
not a member of 'std'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\iomanip(20): note:
see declaration of 'std'
c:\cygwin64\home\user\cpplab7\cs170_vector.h(98): note: while compiling
class template member function 'void cs170::vector<short>::push_back(const T
&)'
with
[
T=short
]
main.cpp(59): note: see reference to function template instantiation 'void
cs170::vector<short>::push_back(const T &)' being compiled
with
[
T=short
]
main.cpp(53): note: see reference to class template instantiation
'cs170::vector<short>' being compiled
c:\cygwin64\home\user\cpplab7\cs170_vector.h(101): error C3861: 'max':
identifier not found
生成文件:
# Macros ========================================
CC = cl
NOLGFLAG = /nologo
CFLAGS = /W4 /WX /Za /EHsc
OBJFLAG = /Fo
EXEFLAG = /Fe
OUTDIR = ms\\
SRC1 = main.cpp
SRC2 =
HDR2 =
OBJ1 = $(OUTDIR)main.obj
OBJS= $(OBJ2) $(OBJ1)
EXE = $(OUTDIR)out.exe
ERASE = rm
MAKEFILE = makefile.ms
# Targets ========================================
$(EXE) : $(OBJS)
$(CC) $(EXEFLAG)$(EXE) $(NOLGFLAG) $(OBJS)
$(OBJ1) : $(SRC1)
$(CC) $(OBJFLAG)$(OBJ1) $(CFLAGS) $(NOLGFLAG) /c $(SRC1)
clean :
-$(ERASE) $(OBJS) $(EXE)
rebuild :
-$(ERASE) $(OBJS) $(EXE)
-$(MAKE) -f $(MAKEFILE) -i
指向此函数的编译器:
#include <iostream>
#include <iomanip>
void push_back(const T& t)
{
if(count+1>capacity)
{
reserve(std::max(2 * capacity, 1));
T* newData = new T[capacity];
for(int i=0; i <count; i++)
{
newData[i] = v[i];
}
delete[] v;
v = newData;
}
v[count++] = t;
}
解决方案
std::max
被定义在<algorithm>
其中你没有包括在内。
#include <algorithm>
推荐阅读
- apache-kafka - Confluent Kafka SMT:时间戳转换问题
- javascript - 此 JavaScript 程序中的控制流程
- r - 更改 facet_wrap、label_both 的变量名
- javascript - 直到 MutationObserver 回调函数彻底执行后页面才会刷新,需要很长时间
- algorithm - 这是一个算法设计问题,需要恒定的时间。我想到了如何使用恒定时间来解决这个问题
- sql-server - SQL 输出 - 包括来自不同表的具有相同时间戳的列
- c# - Sprite 在告诉它移动后没有出现
- java - 无法从 Android Studio 中的 Firebase 获取所有价值
- ios - iPad 的 AVVideoPreviewLayer 重力
- c++ - 为什么我在此代码中收到 SIGABRT 错误