Pointer to struct, containing pointer to an object, for which I want to call a function

Posted by user1795609 on Stack Overflow See other posts from Stack Overflow or by user1795609
Published on 2012-11-02T22:54:06Z Indexed on 2012/11/02 23:00 UTC
Read the original article Hit count: 176

Filed under:

So I've created an ADT which is a singly linked list made up of nodes. These Nodes each have a pointer to an object in them called data.

Class Structure
{
    struct Node
    {
        Object *data;
        Node *next;
    };
};
Node *head;

I am trying to call a function in the object, like this:

head = new Node;
head -> data = new Object();
head -> next = NULL;

cout << head -> data.print();

I keep getting the following error at compile.

error: request for member 'print' in 'head->Structure::Node::data', which is of non-class type 'Object'*

© Stack Overflow or respective owner

Related posts about c++