#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 = ⌖
(*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;
}
Frustrated
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
thx in advance
You are missing a semicolon after your declaration of class "test":
class Name { // stuff}; <-- here
Biggest newbie mistake was stripping out the line numbers for those error messages.
There are other errors reported by VS2005 after fixing this one, but these are obvious and easily fixed.
}; <--- this is missing at the end of the class definitionint 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.
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.
thx again [lol]
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 = ⌖ (*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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement