Я получаю эту ошибку:
g++ -c location.cpp
g++ -c place.cpp
g++ -c popularplace.cpp
g++ -c person.cpp
g++ -o main main.cpp *.o
Undefined symbols for architecture x86_64:
"sim::PopularPlace::arraycounter", referenced from:
sim::PopularPlace::PopularPlace() in popularplace.o
sim::PopularPlace::PopularPlace(double, double) in popularplace.o
"sim::PopularPlace::places", referenced from:
sim::Person::action() in person.o
sim::PopularPlace::PopularPlace() in popularplace.o
sim::PopularPlace::PopularPlace(double, double) in popularplace.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
При создании этого make-файла:
main: main.cpp simulation.h location.o place.o popularplace.o person.o
g++ -o main main.cpp *.o
location.o: location.cpp location.hpp simulation.h
g++ -c location.cpp
place.o: place.hpp place.cpp
g++ -c place.cpp
popularplace.o: place.hpp place.cpp simulation.h popularplace.hpp popularplace.cpp
g++ -c popularplace.cpp
person.o: person.cpp person.hpp location.hpp simulation.h place.hpp place.cpp location.cpp popularplace.o
g++ -c person.cpp
clean:
rm *.o
Я не могу найти ошибку. Вот популярное место. cpp файл:
#include "popularplace.hpp"
#include "simulation.h"
namespace sim{
PopularPlace::PopularPlace()
:open(true){
places[PopularPlace::arraycounter] = this;
PopularPlace::arraycounter++;
}
PopularPlace::PopularPlace(double x, double y)
:Place(x, y), open(true){
places[PopularPlace::arraycounter] = this;
PopularPlace::arraycounter++;
}
bool PopularPlace::isOpen() const{
return open;
}
void PopularPlace::close(int numOfCasesToReopen){
open = false;
}
bool PopularPlace::reopen(int activeCases){
if(activeCases <= numOfCasesToReopen){
open = true;
return true;
} else{
return false;
}
}
}
и вот файл popularplace.hpp:
#ifndef POPULAR_PLACE_HPP
#define POPULAR_PLACE_HPP
#include "simulation.h"
#include "place.hpp"
namespace sim{
class PopularPlace : public Place{
private:
bool open;
int numOfCasesToReopen;
static int arraycounter;
public:
static PopularPlace* places[POPULAR_PLACES];
PopularPlace();
PopularPlace(double x, double y);
bool isOpen() const;
void close(int numOfCasesToReopen);
bool reopen(int activeCases);
};
}
#endif
Если вам нужно, чтобы я предоставил дополнительную информацию / код, я бы будь счастлив сделать это. Спасибо.