Solved

Using char and virtual char in my class.. need help!

Posted on 2007-12-01
3
166 Views
Last Modified: 2010-04-01
I need help instead of using void for menuDisplay() why would I need to use virtual char? and void for menuChoices() how can I use char instead? I am going to create a class called choices that will handle what the choice returns from BaseMenu. right now I am a little lost please help me!
(This is not a class assignment due !)


Here is my code for BaseMenu.h:

class BaseMenu

{

public:

      void menuHeader();

      void menuDisplay();

      void menuChoice();

};
 

Here is the code for BaseMenu.cpp:

#include <iostream>

#include "basemenu.h"

#include "messages.h"

using namespace std;
 

char choice;

bool done = false;

Messages mess;
 

void BaseMenu::menuHeader()

{

      cout << "******************\n";

      cout << "****** MENU ******\n";

      cout << "******************\n";

}

void BaseMenu::menuDisplay()

{

      cout << "***(H)ello     ***\n";

      cout << "***(W)elcome   ***\n";

      cout << "***(O)ther menu***\n";

      cout << "***(Q)uit      ***\n";

      cout << "******************\n";

}

void BaseMenu::menuChoice()

{

      cout << "Choice: ";

      cin >> choice;

      cout << endl;

}
 

now for SubMenu.h

class SubMenu

{

public:

      void newMenu();

};
 

code in SubMenu.cpp:

#include <iostream>

#include "submenu.h"

#include "basemenu.h"
 

using namespace std;

BaseMenu bmenu;
 

void SubMenu::newMenu()

{

      bmenu.menuHeader();

      cout << "***(B)ye       ***\n";

      cout << "***(L)augh     ***\n";

      cout << "***(Q)uit      ***\n";

      cout << "******************\n";

}

Open in new window

0
Comment
Question by:jschmuff
3 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20389843
where is the virtual char issue in your code?
You use virtual when you will have a derived class' method with the same name.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 20390470
Is that what You want(You don't want virtual I guess)
char BaseMenu::menuChoice()
{
      char c;
      cout << "Choice: ";
      cin >> c;
      cout << endl;
      return c;
}
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 20390879
See this post of me in one of your other questions :

        http://www.experts-exchange.com/Programming/Languages/CPP/Q_22995532.html#20390859
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now