Jump to content
  • Advertisement
Sign in to follow this  
bxela1

Frustrated

This topic is 4089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently added classes to my practice code and I get 3 errors, I have checked through my book and can't find why I get the errors. It's probably a really noobie mistake but it's driving me crazy. The errors are error C2628: 'test' followed by 'int' is illegal (did you forget a ';'?) error C2556: 'test test::testx(int)' : overloaded function differs only by return type from 'int test::testx(int)' : see declaration of 'test::testx' : error C2371: 'test::testx' : redefinition; different basic types : see declaration of 'test::testx' and the code is
#include <iostream>
#include <string>
using namespace std;
double &f();
double val = 10;
class test {
	int a;
	int b;
public:
	test();
	int testy(int e);
	int testx(int i);
	int geta();
	int getb();
}

int test::testx(int i)
{
    a=a*i;
}

test::test()
{
	a=0;
	b=0;
	cout << "Class created" << endl;
}

int test::testy(int e)
{
	b=e*e;
}

int test::geta()
{
	return a;
}

int test::getb()
{
	return b;
}

int main()
{
	test v;
	int i;
	int target;
	string word;
	string *wordpoint = &word;
	int *pointer = &target;
	(*pointer) = 25;
	(*wordpoint) = "is target's value";
	cout << target << word << endl;
	cout << f() << " is the current value of val" << endl;
	f() = f() * 10;
	cout << f() << " is the new value of val" << endl;
	cout << "Enter i's value: ";
	cin >> i;
	cout << "i times a = " << v.geta() << endl;
	cout << "i times i = " << v.getb() << endl;
	return 0;
}

double &f()
{
	return val;
}

thx in advance

Share this post


Link to post
Share on other sites
Advertisement
You are missing a semicolon after your declaration of class "test":

class Name {
// stuff
}; <-- here

Share this post


Link to post
Share on other sites
Glare Biggest newbie mistake was stripping out the line numbers for those error messages.

}; <--- this is missing at the end of the class definition

int test::testx(int i) <--- where the (nonsensical) errors start --- in other words, where the compiler has gotten confused


There are other errors reported by VS2005 after fixing this one, but these are obvious and easily fixed.

Share this post


Link to post
Share on other sites
After I fixed it it turned out that a had no value.

After a few mins of moving around of code I came to an end result.


#include <iostream>
#include <string>
using namespace std;
double &f();
double val = 10;
class test {
int a;
int b;
public:
test();
int testy(int e);
int testx(int i);
void geta();
};

void test::geta()
{
cout << "Enter a's value: ";
cin >> a;
}

int test::testx(int i)
{
a=a*i;
return a;
}

test::test()
{
a=0;
b=0;
cout << "Class created" << endl;
}

int test::testy(int e)
{
b=e*e;
return b;
}


int main()
{
test v;
int i;
int e;
int target;
string word;
string *wordpoint = &word;
int *pointer = &target;
(*pointer) = 25;
(*wordpoint) = "is target's value";
cout << target << word << endl;
cout << f() << " is the current value of val" << endl;
f() = f() * 10;
cout << f() << " is the new value of val" << endl;
v.geta();
cout << "Enter i's value: ";
cin >> i;
cout << "Enter e's value: ";
cin >> e;
int testx(int i);
int testy(int e);
cout << "i times a = " << v.testx(i) << endl;
cout << "e times e = " << v.testy(e) << endl;
return 0;
}

double &f()
{
return val;
}



thx again [lol]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!