OK Tôi cần một số thông tin chi tiết.Visual 2010 tiếp tục thông báo cho tôi "lỗi: Biểu thức phải có loại lớp"
Tôi đang tham gia lớp C++ và đang làm việc cho dự án thứ hai của mình. Tôi đang cố gắng tạo danh sách các tùy chọn cho phép bạn lưu trữ email trong một chuỗi vectơ.
Bây giờ trước khi dành thời gian giúp tôi và xem mã tôi muốn chỉ ra vấn đề của mình. Tôi đã thực hiện một đối tượng trong file "HughesProject2-1.cpp":
HughesEmail myhughesEmail();
Vâng vấn đề xuất phát ngay sau này khi tôi sử dụng đối tượng này để chạy displayList():
myHughesEmail.displayList();
trực quan 2010 giữ nói với tôi "lỗi: Biểu thức phải có loại lớp"
Bây giờ tôi đang sử dụng cuốn sách làm tài liệu tham khảo để thực hiện việc này và họ đã tạo một đối tượng theo cùng một cách và sử dụng nó theo cách tương tự ngay sau đó. Tôi bối rối với những gì tôi đã sai khi tệp của tôi hoàn toàn khác với những điều cơ bản của việc sử dụng các đối tượng và những gì đang được thực hiện. Tôi hiểu rằng tôi có các lỗi khác vì điều này là không đầy đủ và tôi vẫn đang học, tôi cần phải biết điều gì có thể khiến tôi không thể sử dụng đối tượng sau khi đã tạo ra nó. Cảm ơn trước.
tôi có ba tập tin:
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();
}
bản sao có thể có của [Sự khác biệt giữa tạo đối tượng với() hoặc không có] (http://stackoverflow.com/questions/5116541/difference-between-creating-object-with-or-without) –
@Charles: I don 't thấy sự cần thiết phải đóng cửa như là một dupe, như tác giả rõ ràng không thể có thể đã tìm thấy câu hỏi đó cho kiến thức hiện tại của mình tại thời điểm yêu cầu. – Puppy
@DeadMG: Đóng! = Xóa. Việc liên kết các câu hỏi giống nhau nhưng khác nhau sẽ giúp người tìm kiếm tiếp theo tìm thấy câu trả lời có liên quan. –