-1

I am creating a class called SelectionPage. Which essentially is a set of menues.

However, when i compile the code, the compiler gives me the following error:

g++ C_Main.cpp C_HomePage.cpp C_SelectionPage.cpp C_MemberManagement.cpp -o Project
C_SelectionPage.cpp:9:104: error: expected initializer before ‘SelectionPage’
make: *** [Project] Error 1

Here is The first few lines of C_SelectionPage.cpp:

#include "H_SelectionPage.h"


//Constructor for the SelectionPage class
//It assigns "managing" which decides if the user
//is a manager or not.
SelectionPage::SelectionPage(
    int newPoints,
    string newManager,
    string newLoginName,
    string MemberFile)
        SelectionPage(
            int newPoints,
            string newManager,
            string newLoginName,
            string MemberFile)
    {
        points = newPoints;
        manager = newManager;
        loginName = newLoginName;
        flatMemberList.clear();
        //Create Object Governing Flat Members.
        memberList = MemberManagement temp(MemberFile);
}

And here is the declaration of the constructor in the header file:

SelectionPage(
    int newPoints,
    string newManager,
    string newLoginName,
    string MemberFile);

Could someone please explain to me why i am getting an error?

Thanks in advance.

Mankarse
  • 39,818
  • 11
  • 97
  • 141
davidx1
  • 3,525
  • 9
  • 38
  • 65
  • 3
    Is that **really** what you have in your C++ file? `SelectionPage::SelectionPage(int newPoints, string newManager, string newLoginName, string MemberFile )**SelectionPage**( int newPoints, string newManager, string newLoginName, string MemberFile){ ` ? – Mat Oct 22 '11 at 10:12

3 Answers3

3

If you have this line really in your code, you probably copied the constructor twice:

SelectionPage::SelectionPage(int newPoints, string newManager, string newLoginName, string MemberFile )SelectionPage( int newPoints, string newManager, string newLoginName, string MemberFile){

Should be this:

SelectionPage::SelectionPage(int newPoints, string newManager, string newLoginName, string MemberFile ){

The compiler complains about intializer list because that's what should follow the header, not another copy of the parameter list.

Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
  • I apologize for my ignorance, I should have spotted it... but after a whole day of coding, i guess i just weren't looking. Thank you very much for pointing out my mistake. – davidx1 Oct 22 '11 at 10:34
1

try adding an access specifier in front of SelectionPage

Jeris
  • 2,355
  • 4
  • 26
  • 38
1

You can perform some of initialization in constructor initialization list and do the rest initialization in constructor body.

SelectionPage::SelectionPage(
  int newPoints, 
  string newManager, 
  string newLoginName, 
  string MemberFile)
  : points(newPoints)
  , manager(newManager)
  , loginName(newLoginName)
  , memberList(MemberFile)
{
  // do the rest initialization here
}
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
ks1322
  • 33,961
  • 14
  • 109
  • 164