我遇到了如下所示的编译错误。我目前正在研究可能会进行哪些更改以修复错误。有人可以告诉我我需要更改吗?我的编译器指出的代码如下。问题也可能在makefile中,但是我不确定要包含什么。任何帮助都非常感谢,谢谢!

编译错误:

 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>

09-16 10:33
查看更多