0

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.

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by mrboolf
0

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

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

to inherit from class A.

0

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!

0

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..?

0

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.

0

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???

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.