#include<iostream.h>

class ADTqueue
{
    private:
        int queue[10];
        int head,tail;

    public:
        ADTqueue()
        {
            tail = -1;
            head = 0;
        }

        int empty()
            {
                if(head == tail+1)
                    return (1);
                else
                    return (0); 
            }

        int full()
        {
            if(tail == 9)
                return (1);
            else
                return (0);
        }

        void append(int num)
        {
            if (!full())
            {
                (tail++);
                    (queue[tail] =num);
            }
        else
        {
            cout<<"Queue is Full"<<endl;
        }
    }

        int serve()
        {
            int num;
            if(!empty())
            {
                (num + queue[head]);
            (head++);
                    return (num);
            }
            else
            {
                cout<<"Queue is Empty"<<endl;
                return (0);
            }
        }

        void main()
        {
            ADTqueue(q);
            q.append(23);
            q.append(46);
            q.append(37);

            cout<<q.serve()<<endl;
            cout<<q.serve()<<endl;
            cout<<q.serve()<<endl;
            cout<<q.serve()<<endl;
        }
};

--------------------Configuration: Cpp1 - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Cpp1.exe - 2 error(s), 0 warning(s)

Assuming this is ALL of the code, you are compiling a component of a program, but it has no main() function. Add a -c flag to the compile CFLAGS (directives). That will generate a .o (Linux/Unix) or .obj (Windows/DOS) file which can be linked to other object files to make a running program.

Execution starts from main(), are you allowed to include main() as a member function of a class ? May be I'm wrong.

Execution starts from main(), are you allowed to include main() as a member function of a class ? May be I'm wrong.

No you are not. main() cannot be part of the class. It must stand alone.

And void main() is wrong. It's int main() -- and always has been. Before you start arguing, it doesn't matter that your instructor taught you it's void, he is wrong. Period. See this.

Hi lim9I,

When you've fixed the above by bringing main() outside of the class, you might want to just check out the following code within serve() to see if it's doing what you're expecting it to do:

if(!empty())
{
    (num + queue[head]);
    (head++);
    return (num);
}

It's close, but there is a problem there that needs addressing.

Good luck with your coding.

Re. WaltP's reply. You can have a main() in Java, but not C++. In C/C++, main() is a global (external) function, and the entry point for the application. No main(), no program - just a part of a program.

This article has been dead for over six months. Start a new discussion instead.