ठीक है मुझे कुछ अंतर्दृष्टि चाहिए।विजुअल 2010 मुझे बता रहा है "त्रुटि: अभिव्यक्ति में कक्षा का प्रकार होना चाहिए"
मैं एक सी ++ कक्षा ले रहा हूं और मेरी दूसरी परियोजना पर काम कर रहा हूं। मैं विकल्पों की एक सूची बनाने की कोशिश कर रहा हूं जो आपको स्ट्रिंग वेक्टर में ईमेल स्टोर करने की अनुमति देता है।
अब मेरी मदद करने के लिए समय निकालने से पहले और कोड को देखने के लिए मैं अपनी समस्या को इंगित करना चाहता हूं।
myHughesEmail.displayList();
दृश्य 2010 रखता है: जब मैं displayList() को चलाने के लिए इस वस्तु का इस्तेमाल किया सही इस के बाद
HughesEmail myhughesEmail();
खैर समस्या आता है: मैं फ़ाइल "HughesProject2-1.cpp" में एक वस्तु बना दिया मुझे बता रहा है "त्रुटि: अभिव्यक्ति में कक्षा का प्रकार होना चाहिए"
अब मैं पुस्तक को ऐसा करने के संदर्भ के रूप में उपयोग कर रहा हूं और उन्होंने एक वस्तु को उसी तरह बनाया है और इसे ठीक उसी तरह उपयोग किया है। मैं जो गलत हूं, उस पर उलझन में हूं क्योंकि मेरी फाइल ऑब्जेक्ट्स का उपयोग करने की मूल बातें और क्या किया जा रहा है, उससे काफी अलग है। मैं समझता हूं कि मेरी अन्य त्रुटियां हैं क्योंकि यह अपूर्ण है और मैं अभी भी सीख रहा हूं, मुझे यह जानने की ज़रूरत है कि मुझे इसे बनाने के बाद ऑब्जेक्ट का उपयोग करने से सबसे अधिक संभावना क्या है। अग्रिम में धन्यवाद।
HughesEmail.cpp
// Classes for HughesProject2-1.cpp and HughesEmail.h
// Includes
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
#include "HughesEmail.h"
// Namespaces
using namespace std;
// Initializing Constructor
HughesEmail::HughesEmail()
{
vector<string> emailStorage(100);
emailMinimumLength = 9;
exitOption = 1;
emailOption = 1;
}
void HughesEmail::displayList()
{
// Check if exit is set, if not run.
if (exitOption == 1)
{
// Email list options
cout << "Choose from the list of options: \n"
"1 - Store an email address.\n"
"2 - Search an email address.\n"
"3 - List all email adresses.\n"
"4 - Delete an email address.\n"
"0 - Exit.\n" << endl;
while (emailOption != 0)
{
// Get user input for email list option
cout << "Option? : ";
cin >> option;
switch (option)
{
case '0':
// set exitOption to 0
exitOption = 0;
emailOption = 0;
break;
case '1':
//Input email name
cout << "Please input email to be stored: " << endl;
cin >> emailName;
// run storeEmail
storeEmail(emailName);
break;
case '2':
// run searchEmail
break;
case '3':
// run listEmail
break;
case '4':
// run deleteEmail
break;
//Ignore
case '\n':
case '\t':
case ' ':
break;
default:
cout << "\nPlease choose a valid option." << endl;
break;
} // end switch
} // end while
} else {
exitOption = 0;
} // end else
}
void HughesEmail::storeEmail(string emailName)
{
// Initialize counter
int i;
i = 0;
// Check if input emailName meets emailMinimumLength
if(emailName.length() >= emailMinimumLength)
{
// if email in vector slot i is less than minimum length, then override with new email.
if (emailStorage[ i ].length() < emailMinimumLength)
{
emailStorage[ i ] = emailName;
} else {
i++;
} // end else
} else {
cout << "Email does not meet the minimum length of: " << emailMinimumLength << " characters." << endl;
} // end else
}
HughesEmail.h
// In this project: HughesProject2.h
// Class header file.
//Includes
#include <string>
#include <iostream>
#include <vector>
//Namespaces
using namespace std;
class HughesEmail
{
public:
HughesEmail();
void displayList();
void storeEmail(string);
string searchEmail(string);
string listEmail();
void deleteEmail();
private:
vector<string> emailStorage;
int emailMinimumLength;
int emailOption;
int exitOption;
char option;
string emailName;
};
HughesProject2-1.cpp
// In this project: HughesProject2-1.cpp
// Class creation to store email adresses. Adding, deleting, searching and listing email addresses.
// Includes
#include <string>
#include <iostream>
#include <vector>
#include "HughesEmail.h"
// Namespaces
using namespace std;
int main()
{
//Create HughesEmail Object
HughesEmail myHughesEmail();
myHughesEmail.displayList();
}
:
मैं तीन फ़ाइलें
संभावित डुप्लिकेट [ऑब्जेक्ट() या बिना ऑब्जेक्ट बनाने के बीच अंतर (http://stackoverflow.com/questions/5116541/difference-between-creating-object-with-or-without) –
@ चार्ल्स: मैं नहीं करता एक डुप्ली के रूप में बंद होने की आवश्यकता को नहीं देखता है, क्योंकि लेखक स्पष्ट रूप से यह नहीं पाया कि प्रश्न पूछने के समय उस प्रश्न को अपने मौजूदा ज्ञान को दिया गया है। – Puppy
@DeadMG: बंद करें! = हटाएं। समान लेकिन अलग-अलग शब्दों वाले प्रश्नों को जोड़ने से बाद के खोजकर्ताओं को संबंधित उत्तरों मिलते हैं। –