[问题] 出现MAX was not declared in the scope

楼主: c2147369 (stitch)   2016-07-12 13:34:39
求解在编译的最后跑出来MAX was not declared in the scope。
main.cpp
#include <iostream>
#include <iomanip>
#include "vector.h"
using namespace std;
const int MAX = 100;
int main() {
int a1[] = {0,1,2,3,4,5,6,7,8,9};
int s1=sizeof(a1)/sizeof(int);
vector v1(a1,s1);
v1.dump();
vector v2(v1);
v2.set(13,88);
v2.dump();
vector v3(v1);
v3.resize(6);
v3.dump();
vector v4(v1);
v4.resize(15);
v4.dump();
system("pause");
return 0;
}
vector.h
class vector {
private:
int dat[MAX];
int size;
public:
vector();
vector(int d[], int s);
vector(const vector & v) ;
void set(int index, int v) ;
int get(int index) ;
void resize(int s) ;
void dump() ;
};
vector.cpp
#include <iostream>
#include <iomanip>
#include "vector.h"
using namespace std;
vector::vector() {
size=0;
}
vector::vector(int d[], int s) {
size=(s<=MAX)?s:MAX;
for(int i=0; i<size; i++)
dat[i]=d[i];
}
vector::vector(const vector & v) {
size = v.size;
for(int i=0; i<size; i++)
dat[i]=v.dat[i];
}
void vector::set(int index, int v) {
if (index<size)
dat[index]=v;
else if (index<MAX) {
while (size<index)
dat[size++]=0;
dat[size++]=v;
} else
cout<<"ERROR: index is out of range!"<<endl;
}
int vector::get(int index) {
if (index<size)
return dat[index];
else
cout<<"ERROR: index is out of range!"<<endl;
return 0;
}
void vector::resize(int s) {
if (s<size)
size=s;
else
while (size<=s)
dat[size++]=0;
}
void vector::dump() {
for(int i=0; i<size; i++)
cout<<setw(5)<<dat[i];
cout<<endl;
}
http://i.imgur.com/6pyUaqM.jpg
求解谢谢大家~~
作者: bibo9901 (function(){})()   2016-07-12 14:59:00
c++的全域 const 只有所在的.cpp才看得到
作者: Caesar08 (Caesar)   2016-07-12 15:04:00
假小妹?如果vector.h有extern的话就看的到
作者: ilms49898723 (LittleBird)   2016-07-12 15:24:00
现在好流行自称小妹或说是女的,有buff?
作者: TobyH4cker (Toby (我要当好人))   2016-07-14 12:06:00
小妹我也不是故意的啦

Links booklink

Contact Us: admin [ a t ] ucptt.com