Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:07:13+00:00 2026-06-13T03:07:13+00:00

Possible Duplicate: Is no parentheses on a constructor with no arguments a language standard?

  • 0

Possible Duplicate:
Is no parentheses on a constructor with no arguments a language standard?

Okay, I’ve got a pickle. It’s an error C2228 issue, and I’ve looked at other questions and answers, and none of the tips given seem to work for me- this is my first question, and I’m a newbie, so please be gentle! Note: The program WILL compile if I use

Wizard wiz0; 

but NOT if I use

Wizard wiz0();

The book I am using tells me that these two statements should be equivalent, so I am trying to figure out why I can use one and not the other.

First off, here is the error when I attempt to use Wizard wiz0():

1>  Chapter5.cpp
1>Chapter5.cpp(14): error C2228: left of '.fight' must have class/struct/union
1>Chapter5.cpp(15): error C2228: left of '.talk' must have class/struct/union
1>Chapter5.cpp(17): error C2228: left of '.setArmor' must have class/struct/union
1>Chapter5.cpp(19): error C2228: left of '.getName' must have class/struct/union
1>Chapter5.cpp(21): error C2228: left of '.castSpell' must have class/struct/union

Here is (what I think) the relevant code from Chapter5.cpp is:

Wizard wiz0(); //declares a variable (wiz0) of type Wizard.

wiz0.fight();
wiz0.talk();

wiz0.setArmor(10);

cout << "Player's Name: " << wiz0.getName() << endl;

wiz0.castSpell();

Also, here is the information from wiz.h file:

public
//Constructor
Wizard();

//Overloaded Constructor
Wizard(std::string name, int hp, int mp, int armor);

//Destructor
~Wizard();

//Methods
void fight();
void talk();
void castSpell();
void setArmor(int mArmor);
std::string Wizard::getName();

private:
//Data members
std::string mName;
int mHitPoints;
int mMagicPoints;
int mArmor;

…and finally, information from the wiz.cpp file!

//Wiz.cpp implementation file

#include "stdAfx.h"
#include "wiz.h"
using namespace std;

//The Constructor call
Wizard::Wizard()
{
/*If the client calls a constructor without
specifying values, these will be the default
values that the program will use */
mName = "DefaultName";
mHitPoints = 1;
mMagicPoints = 1;
mArmor = 0;
}

Wizard::Wizard(std::string name, int hp, int mp, int armor)
{
//Client called constructor WITH values, so create an
//object with them.
mName = name;
mHitPoints = hp;
mMagicPoints = mp;
mArmor = armor;
}

void Wizard::fight()
{
    cout << "Fighting." << endl;
}

void Wizard::talk()
{
    cout << "Talking." << endl;
}

void Wizard::castSpell()
{
    if (mMagicPoints < 4)
        cout << "Casting spell." << endl;
    else
        cout << "Not enough MP!" << endl;
}

void Wizard::setArmor(int armor)
{
    if(armor >= 0)
        mArmor = armor;
} 

std::string Wizard::getName()
{
return mName;
}

Wizard::~Wizard()
{
//Not using dynamic memory- nothing to clean
}

Phew… I think that’s everything. If you guys can figure out what it is I’m doing wrong, I’d greatly appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:07:14+00:00Added an answer on June 13, 2026 at 3:07 am

    It’s a weird part of the way C++ is parsed. The one with parentheses is interpreted as a function prototype. You should use the one without the parentheses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is no parentheses on a constructor with no arguments a language standard?
Possible Duplicate: Why are C# 3.0 object initializer constructor parentheses optional? What is the
Possible Duplicate: Why are C# 3.0 object initializer constructor parentheses optional? Hi all I
Possible Duplicate: Default constructor with empty brackets Instantiate class with or without parentheses? Program:
Possible Duplicate: C Macros and use of arguments in parentheses I found this macro
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Why following code
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? What does (function($)
Possible Duplicate: What's the role of the parentheses in the following piece of code?
Possible Duplicate: Parentheses at the end of a C++11 lambda expression #include <iostream> int
Possible Duplicate: Why to use empty parentheses in Scala if we can just use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.