My wife and I have a problem with the contents of our refrigerator. Fridge is full of stuff, and we have very little idea of what's in there/how long it's been in there. I had the idea of creating some kind of inventory system to keep track of what goes in the fridge and when it should be removed, etc, etc. Granted, I just started designing this solution today, so it's not very well fleshed out. I'm sure that over time (as I gain more experience with designing these things) my skill will improve.
My design:
I was going to have a single Fridge object, holding multiple FridgeItem* objects. I created my two classes, and a main.cpp to call them. I then copied over a Makefile from a project I was working on a LONG time ago, and altered it to reflect my current project.
Here are my files (so far):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#ifndef _fridgeitem_
#define _fridgeitem_
#include <string>
class FridgeItem
{
public:
FridgeItem();
~FridgeItem();
std::string getName();
int getCount();
private:
std::string name;
};
#endif
michael@caitlyn fridge $ cat FridgeItem.cpp
#include "FridgeItem.h"
FridgeItem::FridgeItem()
{
}
FridgeItem::~FridgeItem()
{
}
michael@caitlyn fridge $ cat Fridge.h
#ifndef _FRIDGE_
#define _FRIDGE_
#include "FridgeItem.h"
class Fridge
{
public:
Fridge();
~Fridge();
bool add(FridgeItem* item);
//bool remove
int getCount(); //Returns total number of FridgeItems
void printCount(); //Prints number returned by getCount;
private:
int count;
};
#endif
michael@caitlyn fridge $ cat Fridge.cpp
#include "Fridge.h"
#include <iostream>
using namespace std;
Fridge::Fridge()
{
count = 0;
cout << "I'm here!" << endl;
}
Fridge::~Fridge()
{
}
bool Fridge::add(FridgeItem* item)
{
//Other add stuff
count++; //Increase the counter last of all
}
//bool Fridge::remove
int Fridge::getCount() //Returns total number of FridgeItems
{
return count;
}
void Fridge::printCount()
{
cout << "Number of items currently in the fridge: " << getCount() << endl;
}
michael@caitlyn fridge $ cat main.cpp
#include "Fridge.h"
Fridge* fridge;
int main()
{
fridge = new Fridge();
fridge->printCount();
// delete fridge; //We must clean up after ourselves.
return 0;
}
michael@caitlyn fridge $ cat Makefile
CXX=g++
CFLAGS=-ggdb -H -W -Wall -pedantic -dH
LIBS=
OBJS = Fridge.o FridgeItem.o
INCS = Fridge.h FridgeItem.h
all: main
main: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LIBS)
%.o : %.cpp $(INCS)
$(CXX) $(CFLAGS) -c $<
clean:
-rm *.o *~ core* vgcore* main
|
Now, the problem I am having:
1 2 3 4 5 6 7 8 9
|
michael@caitlyn fridge $ make
g++ -o main Fridge.o FridgeItem.o
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../lib64/crt1.o: In function `_start':
/glibc-tmp-95e0907d753adfc89f1c416310f2df8c/glibc-2.23/csu/../sysdeps/x86_64/start.S:114: undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:14: recipe for target 'main' failed
make: *** [main] Error 1
michael@caitlyn fridge $
|
I'm going to go do more digging into this undefined reference thing, because I feel like I used to know how to fix it myself.