Problem with calling function from derived class by base class

I can't figure out why the Node Class is unable to call the derived class Grocery to set the Item.

The Grocery class is a derived class of the Node class.

1
2
3
4
5
6
Node::Node(std::string a,std::string b)
{
	Grocery::setItem(a);
        Grocery::setQuantity(b);
	Node::setNext(NextPTR);
}


errors are:
1
2
3
4
5

error C2352: 'Grocery::setItem' : illegal call of non-static member function
grocery.h(33) : see declaration of 'Grocery::setItem'
error C2352: 'Grocery::setQuantity' : illegal call of non-static member function
grocery.h(37) : see declaration of 'Grocery::setQuantity'


this is the snipet from the grocery.h file
1
2
3
4
5
6
7
8
9
10
11
#pragma once
#include "Classes.h"

class Grocery: public Node
{
public:

    void Grocery::setItem(std::string I);
    void Grocery::setQuantity(std::string I);
};


a snipet from the Classes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include <string>
#define NULL 0

class Node
{
private:
	Node* NextPTR;

public:
        Node(std::string a,std::string b);

};



I think it is either I am missing something or maybe it is just in the wrong order.
can anyone help on this one do I need to include more information?
The Grocery class is a derived class of the Node class. 


That is correct, meaning the Grocery class can access all of the Nodes public/protected members. However in this example you are trying to call a Grocery function inside of a Node function which will not work.

You will have to use
class Node : public Grocery
for it to work how you want it to by the look of it.
that did it I totally had that backwards.
Topic archived. No new replies allowed.