类向量上的C 汇编问题

C++ compilation issue on class vector

本文关键字:汇编 问题 向量      更新时间:2023-10-16

我在汇编误差方面遇到困难,如下所示。我目前正在研究可能会更改的内容以解决错误。有人可以告诉我我需要改变什么吗?我的编译器指出的代码在下面。问题也可能出现在Makefile中,但我不确定要包含什么。任何帮助都非常感谢!

编译错误:

 C:cygwin64homeusercpplab7>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:cygwin64homeusercpplab7cs170_vector.h(101): error C2039: 'max': is 
not a member of 'std'
C:Program Files (x86)Microsoft Visual 
Studio2017CommunityVCToolsMSVC14.16.27023includeiomanip(20): note: 
see declaration of 'std'
c:cygwin64homeusercpplab7cs170_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:cygwin64homeusercpplab7cs170_vector.h(101): error C3861: 'max': 
identifier not found

makefile:

# 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>