Okay, I cannot figure this out. I still get the same error:

Error 1 error C2039: 'function' : is not a member of 'D'

Here's what I have:

Class A.h:

#pragma once
#include <string>
using namespace std;

class D;

class A
{
    public:
		void function(string s);
		friend class D;
        
    private:
        string name;
        string email;
        
    };

Class D.h:

#pragma once
#include <vector>
#include "A.h"

class L;
class ListOfD;

class D
{
	public:
		friend class L;
		friend class ListOfD;
        
    private:
              //not important right now
};

Class L.cpp(this is where the error is):

#include "L.h"
string L::somethingnotimportant(string & command)
{
    string result;
    if(command.substr(0,4)=="some")
	{
		string parameter=command.substr(5,9999);
		D p;
    --------->   p.function(parameter);
		lop.lastID++;
		p.patronIdNumber = lop.lastID;
		lop.add(p);		
	}
	else if(command == "PRINTP")
	{
		//result = printp();
	}
    else if(command == "QUIT")
    {
        result = "Goodbye!";
    }
    else
    {
        result = "UNKNOWN COMMAND";
    }
    
    return result;
}

Okay, I think thats enough code to see the problem. I left out some information, so no one steals this code. Anyways, the function from class A is suppose to be inherited from class D, as well as the two string variables, right? Because nothing from class A can be used unless I create a new object A.

Your D class does not inherit from class A. You should write

class D : A
{
// your code here
};

to inherit from class A.

Thanks a lot for your help. I thought that if you included the header file in the other class, then it would inherit it (at least, thats what the professor said). Thanks again!

ughhh...okay, class D is now able to access class A's function (yay!), but now it doesn't seem to be able to access the private members. Why? I thought when you used friend operator, it allows access to private members..?

ughhh...okay, class D is now able to access class A's function (yay!), but now it doesn't seem to be able to access the private members. Why? I thought when you used friend operator, it allows access to private members..?

Not sure, change them to protected should work though.

Not sure, change them to protected should work though.

yea, you're right, it does work. Unfortunately, the private members need to be private. So what should I do???

Protected means private but inherited like private (hence accessible) by derived classes. If you declare them protected they'll behave just like if they're private. There's a table in the link I posted before that summarizes it.

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