Hello,

I have a question about classes on C++.

So far I have 3 classes on my project. BibEntry ( abstract class), KeyFinder (class to find the \cite in file and store to private KEY at abstract) and TypeFinder ( class to find which entry is it article, journal so on )

overloaded ifstream in KeyFinder will find the key in .tex file and use the method setKey from abstract class to store it
overloaded ifstream in Type Finder will find the type from the key obtained from abstract class.

I had this snippet on main function

BibEntry *entry = 0;
  KeyFinder key;
  TypeFinder type ;
 
  infile1 >> key;
  infile2 >> type;
 
  entry = &key;
  cout<<entry->getKey()<<endl;

  entry = &type;
  cout<<entry->getKey()<<endl;

MY QUESTION IS : How come when I call key.getKey the searched key appears on display but type.getKey won't appear on display. Also, why is it that during the overloaded stream for TypeFinder the command type.getKey appears empty?

Both my classes inherit from abstract class so both of them should have access to private data KEY in abstract class. I'm very confused. I tried casting it to (TypeFinder) key but compiler didn't allow.

What can I do so that both TypeFinder and KeyFinder can access the same Key that the stream over loader had set ?

I attached all my files for your convenience. please remove the .doc extension for the input files.

Q1:
"key.getKey the searched key appears on display but type.getKey won't appear on display"??
A1:
easy the first file contains \cite so the keyfinder found it and store it in key
and the second file found the type but store it in type so the key is empty

Q2: i didnot understand what you want to do but if you are asking about to subclasses to share variable from parent use static modifire

I may be wrong, but I believe "protected" members of a base class are inherited by subclasses, while "private" members are indeed private to the base class, and are -not- inherited (or at least are not accessible) in subclasses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.