Alex Rivera | Logout

Visual 2010 keeps telling me "error: Expression must have class type"

Asked 2011-03-02T12:38:29.427
12

Okay I need some insight.

I am taking a C++ class and am working on my second project. I am trying to create a list of options that allow you to store emails in a string vector.

Now before taking the time to help me and look at the code I want to point out my problem. I made an object in the file "HughesProject2-1.cpp":

HughesEmail myhughesEmail();

Well the problem comes right after this when I used this object to run displayList():

myHughesEmail.displayList();

Visual 2010 keeps telling me "error: Expression must have class type"

Now I am using the book as a reference to doing this and they created an object the same way and used it the same way right after. I am confused at what I have wrong as my file is quite different past the basics of using the objects and what is being done. I understand there my be other errors as this is incomplete and I'm still learning, I need to know what is most likely causing me from using the object after I made it. Thanks in advance.

I have three files:

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 )
  
Edit
Report

1 Answer

39

You've run into something called the most vexing parse.

HughesEmail myHughesEmail();

This line does not construct a new HughesEmail object on the stack. Rather, it declares a function that returns a HughesEmail and takes nothing. You should remove the empty parentheses.

answered 2011-03-02T12:44:14.107

Your Answer