Members Online
Total Online: 25 Web Spiders: 15
Guests Online: 25
Members Online: 0
Registered Members: 70170 Newest Member: bahmx
|
View Thread
| Author |
C++ Linker issue |
Zkunxen
Member
Posts: 47
Location:
Joined: 24.07.09 Rank: Elite |
|
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? |
|
| Author |
RE: C++ Linker issue |
Apophis
Member
Posts: 86
Location:
Joined: 02.10.09 Rank: Moderate |
|
Why did you start a new thread for this?
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?
|
|
| Author |
RE: C++ Linker issue |
Zkunxen
Member
Posts: 47
Location:
Joined: 24.07.09 Rank: Elite |
|
|
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. |
|
| Author |
RE: C++ Linker issue |
Recursacro
Member

Posts: 33
Location: ~
Joined: 08.10.09 Rank: Moderate |
|
Zkunxen wrote:
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.
Anyone correct me if I'm wrong, but a friend cannot access private data. Friends and family can access protected data though.
"Your worst enemy cannot harm you as much as your own unguarded thoughts." - The Buddha
"In fact, everything we encounter in this world with our six senses is an inkblot test. You see what you are thinking and feeling, seldom what you are looking at." - Shiqin
Edited by Recursacro on 10-10-09 03:15 |
|
| Author |
RE: C++ Linker issue |
ynori7
Future Emperor of Earth

Posts: 1481
Location: #valhalla
Joined: 08.10.07 Rank: Diabolical |
|
|
Recursacro wrote:
Anyone correct me if I'm wrong, but a friend cannot access private data. Friends and family can access protected data though.
No, I'm pretty sure the purpose of making a class a friend is so it can access data in your private fields.
|
|
| Author |
RE: C++ Linker issue |
Zkunxen
Member
Posts: 47
Location:
Joined: 24.07.09 Rank: Elite |
|
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) |
|
| Author |
RE: C++ Linker issue |
ynori7
Future Emperor of Earth

Posts: 1481
Location: #valhalla
Joined: 08.10.07 Rank: Diabolical |
|
Just out of curiosity, why are you using a linked list? This is a money/account related program right? Wouldn't a vector work better?
|
|
| Author |
RE: C++ Linker issue |
Zkunxen
Member
Posts: 47
Location:
Joined: 24.07.09 Rank: Elite |
|
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. |
|
|
|
|