Follow us on Twitter!
It is the path of least resistance that makes rivers and men crooked. - Bj Palmer
Sunday, April 20, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 30
Guests Online: 28
Members Online: 2

Registered Members: 82850
Newest Member: hardstylurr
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ Linker issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-10-09 21:44
well, finally almost done, but now I get this:
Code

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:
Code

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-10-09 22:01
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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 09-10-09 22:51
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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 10-10-09 03:14
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.




Edited by on 10-10-09 03:15
Author

RE: C++ Linker issue

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 10-10-09 03:35
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.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: C++ Linker issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 11-10-09 02:19
from http://www.cplusp. . .nheritance/:
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
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 11-10-09 03:29
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?


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: C++ Linker issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 12-10-09 21:17
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.