error C2589: '(' : illegal token on right side of '::'

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

error C2589: '(' : illegal token on right side of '::'

Postby Sun Stealer » Tue Oct 21, 2003 3:55 pm

This is my .cpp implementation code for a class called Banner_2:

#include "banner_2.h"
#include <iostream>
#include <string>
using namespace std;

Banner_2::Banner_2() :favoriteProgram("C++")
{
cout << "Banner's Constructor" << endl;
}

Banner_2::(string param1);
{
cout << "Banner's Overloaded Constructor" << endl;
favoriteProgram = param1;
}

void Banner_2::Display()
{
cout << "I love " << favoriteProgram << endl;
}




This is my .h header file code for this class:

#include <iostream>
#include <string>
using namespace std;

class Banner_2
{
public:
Banner_2();
Banner_2(string param1);
void Display();

private:
string favoriteProgram;
};





And this is the the "startup" code that instantiates the objects:

#include "banner_2.h"

void main()
{
Banner_2 x;
x.Display();

Banner_2 y("Java");
y.Display();
}


If someone could please explain why I'm receiving these three following error messages, I would greatly appreciate it: '(' : illegal token on right side of '::' error C2059: syntax error : '::'
'{' : missing function header (old-style formal list?)
Sun Stealer
 
Posts: 3
Joined: Sun Oct 12, 2003 9:46 pm

Postby Jimbo » Tue Oct 21, 2003 4:37 pm

since you omitted a line number, this is a guess at your problem (but it is a definite problem)

Banner_2::(string param1);


you never said which function you are defining here. i think you meant something like
Code: Select all
Banner_2::Banner_2(string param1);
User avatar
Jimbo
 
Posts: 601
Joined: Thu Sep 25, 2003 6:48 pm
Location: Seattle

Postby Justin » Tue Oct 21, 2003 9:30 pm

After you get rid of your problem, I suggest that you also get rid of the constructor
Code: Select all
Banner_2();

in the .h and .cpp and change
Code: Select all
Bannery_2(string param1);

to
Code: Select all
Bannery_2(string param1="C++");

in the .h

This may just be preference, but it also makes your code smaller. Also, it's less coding for you to do (in the future).
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA


Return to For Beginners

Who is online

Users browsing this forum: Google [Bot] and 0 guests