i keep getting these errors with my program and i was wondering if anyone can help.

/tmp/cc2Rxau2.o: In function `main':
prac.cpp:(.text+0x101): undefined reference to `Barcode::Barcode()'
collect2: ld returned 1 exit status


#include <iostream>

using namespace std;

class Barcode

        Barcode(int zipcode);

        Barcode(char bar);


        int convert(int num);


        int return_bar();

        int return_zip();


int main()
        int choice;
        int usrzip;
        Barcode zip;
        cout << "enter 1 if you want to change a zipcode to barcode, or a 2 for a barcode to zipcode." << endl;

        cin >> choice;

        if(choice == 1)
                cout << "enter your 5 digit zipcode." << endl;
                cin >> usrzip;

                int num1, num2, num3, num4, num5;
                int temp1, temp2, temp3, temp4;
                int bar_num1, bar_num2, bar_num3, bar_num4, bar_num5;

                num1 = usrzip % 10;
                temp1 = usrzip / 10;
                num2 = temp1 % 10;
                temp2 = temp1 / 10;
                num3 = temp2 % 10;
                temp3 = temp2 / 10;
                num4 = temp3 % 10;
                temp4 = temp3 / 10;
                num5 = temp4 % 10;

        cout << num5 << " " << num4 << " " << num3 << " " << num2 << " " << num1 << endl;              

                bar_num1 = zip.convert(num1);
                bar_num2 = zip.convert(num2);
                bar_num3 = zip.convert(num3);
                bar_num4 = zip.convert(num4);
                bar_num5 = zip.convert(num5);

        cout << bar_num5 << bar_num4 << bar_num3 << bar_num2 << bar_num1 << endl;



int Barcode :: convert(int num)
        char result;
                case 1:
                        result = 00011;
                case 2:
 result = 00101;
                case 3:
                        result = 00110;
                case 4:
                        result = 01001;
                case 5:
                        result = 01010;
                case 6:
                        result = 01010;
                case 7:
                        result = 10001;
                case 8:
                        result = 10010;
                case 9:
                        result = 10001;
                        cout << "not valid choice." << endl;


Edited by mike_2000_17: Fixed formatting

8 Years
Discussion Span
Last Post by jonsca

You have declared three different constructors for Barcode: Barcode(int zipcode); Barcode(char bar); and Barcode() If you declare any other constructors and then a default one, you must define that default constructor (in fact in your file you don't have _any_ of them defined).

Edited by jonsca: n/a


could you help me with how to define the constructors and how i to use them in my program.

Barcode::Barcode(int zipcode)
          take in zipcode, convert it (with the built in function )and assign to internal barcode value


Barcode::Barcode(char Bar)
set internal barcode to value passed in


     do nothing or establish defaults (ex. barcode = 00000 or zipcode = 00000  


Since you have no private variables to assign any of these to, you need to make some. Check on what your text has to say about them.

These c'tor definitions would go before your Barcode::convert() definition.

Looking back, probably your best bet in main would be to not use your convert function statically but to create individual barcode objects.

Skim over your text on instantiating objects out of your classes. In summary, you probably need an overhaul but it shouldn't be too involved.

P.S. I'm not trying to cast you off or anything, far from it, I just think you should rethink the requirements a bit more. You have a couple of good functions with your class, but what is the most effective way to use them so your code is object oriented. You want your objects to be initially given a barcode or be given a zipcode to convert to a barcode. How can you store all of that content into that one piece of information.

Edited by jonsca: Added info

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.