简体   繁体   中英

C++ compilation issue on class vector

I am having a hard time with the compilation error as shown below. I am currently looking at what could potentially be changed to fix the error. Could anyone here tell me what I need to change? The codes that my compiler is pointing out is below. The problem could also be in the makefile but I am not sure about what to include. Any help is much appreciated thanks!

Compilation error:

 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

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

Compiler pointing to this function:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM