user2793442
user2793442

Reputation: 129

How to use struct functions in a class outside of main?

I am attempting to use functions that return a pointer, but I am not sure how to declare them.

Here's my function as I have it currently written, item is the name of my struct, queue is the name of my class - if it were to just be written in main it would simply be: item * divide(item *a):

item queue:: *divide(item *a)
{
    item *b, *c;
    b = a;
    c=a->next;
    c=c->next;
    while(c != NULL)
    {
         c=c->next;
         b=b->next;
         if (c!=NULL)
             c=c->next;
    }
c=b->next;
b->next = NULL;
return c;
}

What would the correct approach be?

Upvotes: 0

Views: 88

Answers (2)

maddin45
maddin45

Reputation: 747

I guess queue is the class you are mentioning in the title of your question?

The * is part of the return type of your function, which stands in front of the scope queue. So the correct way to define your finction would be

item * queue::divide(item *a)
{
    ...
}

Upvotes: 1

Martin Drozdik
Martin Drozdik

Reputation: 13313

You should declare the function as:

item* queue::divide(item *a);

Upvotes: 2

Related Questions