C++ Linker issue
well, finally almost done, but now I get this:
Linking console executable: bin/Debug/cashReg
Undefined symbols:
"LinkList<Sale::item>::toArray()", referenced from:
Sale::showOrder() in cashReg.o
"LinkList<Sale::item>::pushBack(Sale::item)", referenced from:
Sale::addItem(double, bool)in cashReg.o
Sale::coupon(double)in cashReg.o
"LinkList<Sale::item>::~LinkList()", referenced from:
Sale::~Sale() in main.o
"LinkList<Sale::item>::length()", referenced from:
Sale::showOrder() in cashReg.o
"LinkList<Sale::item>::LinkList()", referenced from:
Sale::Sale() in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I have no idea what to do here. and my code is, all in all, 520 lines long.
here's the functions that are referencing the link list member functions:
void Sale::showOrder(){
int aLength=order->length();//here
item* a=new item[aLength];
a=order->toArray();//here
for(int i=0;i<aLength;i++){
if(a[i].Taxable)
std::cout << "T";
else
std::cout << " ";
std::cout << "\t";
//std::cout << a[i].name;
//std::cout << "\t";
std::cout << a[i].price << std::endl;
}
delete a;
}
double Sale::addItem(double cost,bool hasTax)
{
buffer.number=num;
++num;
buffer.price=cost;
buffer.Taxable=hasTax;
order->pushBack(buffer);//here
Subtotal+=cost;
if(hasTax){
taxableTotal+=cost;
taxTotal=(taxableTotal*TAX)+.005;
}
if(isTaxExempt){
taxTotal=0;
}
Total=(Subtotal+taxTotal);
return cost;
}
double Sale::coupon(double amount)
{
if(amount<=Subtotal){
Subtotal-=amount;
buffer.number=num;
++num;
buffer.price=-amount;
buffer.Taxable=0;
order->pushBack(buffer);//here
return Total=Subtotal+taxTotal;
}
else{
std::cout << "Coupon may not exceed total." << std::endl;
return -1;
}
}
~Sale(){delete order;}//in header
Sale()
{
Subtotal=0;
taxTotal=0;
Total=Subtotal+taxTotal;
itemCount=0;
paid=false;
isTaxExempt=false;
spent=0;
num=1;
order=new LinkList<item>();//here
}
Sale(const char* orderId){
std::ifstream collect;
num=1;
order=new LinkList<item>();
char* retrieve=strcat("orders/",orderId);
collect.open(retrieve);
std::string s;
while(!collect.eof()){
buffer.number=num;
++num;
collect >> s;
std::stringstream(s.c_str()) >> buffer.price;
collect >> s;
std::stringstream(s.c_str()) >> buffer.Taxable;
order->pushBack(buffer);//and here
}
collect.close();
}
any suggestions?
Apophis wrote: Why did you start a new thread for this?
sorry, I should have added on to old thread
Apophis wrote: So your lists are of the type "Sale::item" yes? What exactly does that mean? What is an item? It looks like it must be an object that you defined, so shouldn't it be a list of just item objects? an item is a struct defined in my class Sale. I've tried defining it as public and private, and I've defined it before my class, I tried specifying every member function of my linklist class as friends, so they could access it as private, I even tried putting the #include after its definition, nothing seems to works.
Zkunxen wrote: [quote]Apophis wrote: Why did you start a new thread for this?
sorry, I should have added on to old thread
Apophis wrote: So your lists are of the type "Sale::item" yes? What exactly does that mean? What is an item? It looks like it must be an object that you defined, so shouldn't it be a list of just item objects? an item is a struct defined in my class Sale. I've tried defining it as public and private, and I've defined it before my class, I tried specifying every member function of my linklist class as friends, so they could access it as private, I even tried putting the #include after its definition, nothing seems to works.[/quote]
Anyone correct me if I'm wrong, but a friend cannot access private data. Friends and family can access protected data though.
from http://www.cplusplus.com/doc/tutorial/inheritance/: In this example, we have declared CRectangle as a friend of CSquare so that CRectangle member functions could have access to the protected and private members of CSquare, more concretely to CSquare::side, which describes the side width of the square.
I'm completely lost here, I could post the code, but I don't think 520 lines of code would fit very well… and even with just the files that seem to be causing the issue, that's still the majority of the code… (I think it's all but the linklist.h file)
it would, but I wrote the linked list class myself, and I wanted to use it. also, if the order gets really large (probably larger than would be likely) wouldn't the program start to become slow with vectors, because it has to rewrite the entire internal array, and delete the original with every pushback, and at the same time, I don't want to allocate enough memory for 50 items for an order containing three. that's horribly inefficient. and what about removing an arbitrary item from the order? that would require rewriting the entire vector, whereas with a linked list I can remove an item from anywhere in the order with a single class method.