program won't identify class

I am having trouble with my program. For some reason, I cannot set my class up, resulting in an error C2236.
1
2
3
4
5
6
class ComplexTest 
{
public:
	ComplexTest();
	void Run();
};

The weirdest this is that whenever I move my cursor to ComplexTest it says "class ComplexTest".
Can someone help me? Because virtually all of my errors stems down from this.

I also have a class named Complex, does that have anything to do with it?
Last edited on
This should not be a C2236 error, the problem is somewhere else.

No problem:
1
2
3
4
5
6
7
8
9
10
11
class ComplexTest 
{
public:
	ComplexTest() { }
	void Run();
};

int main(void){
	ComplexTest test;
	return 0;
}


Thank you, but this is a header file. I'm sorry I did not clarify that.
Also this what my Output window is saying
"1>c:\users\owner\documents\visual studio 2010\projects\lab10\complextest.hpp(19): error C2236: unexpected 'class' 'ComplexTest'. Did you forget a ';'?"
Last edited on
Somewhere you are forgetting a ";", but it has nothing to do with the code you posted.

Note that the class was unexpected, it was expecting something different before the class. Just chance that ComplexTest was where something wrong actually happened.
Last edited on
Actually I think I better post the entire program.
Here's my main .cpp
1
2
3
4
5
6
7
#include "ComplexTest.hpp"

int main() {
	ComplexTest test;
	test.Run();
	return 0;
}
Complex.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef COMPLEX_HPP
#define COMPLEX_HPP

#include <string>

using namespace std;

class Complex
{
private:
    double mReal;
    double mImag;
public:
    Complex();
    Complex(double pInitReal, double pInitImag);
    Complex Add(Complex& pRHSOp);
    Complex Div(Complex& pRHSOp);
    double GetImag();
    double GetReal();
    Complex Invert();
    Complex Mult(Complex& pRHSOp);
    Complex Negate();
    void SetImag(double pNewImag);
    void SetReal(double pNewReal);
    Complex Sub(Complex& pRHSOp);
    string ToString();
    void Init(double pInitReal, double pInitImag);
}

#endif 
Complex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iomanip>
#include <sstream>
#include "Complex.hpp"

using namespace std;

Complex::Complex()
{
    Init(0, 0);
}

Complex::Complex(double pInitReal, double pInitImag)
{
    Init(pInitReal, pInitImag);
}

Complex Complex::Add(Complex& pRHSOp)
{
    double sumReal = GetReal() + pRHSOp.GetReal();
    double sumImag = GetImag() + pRHSOp.GetImag();
    Complex sum;
    sum.Complex::Complex(sumReal, sumImag);
    return sum;
}

Complex Complex::Div(Complex& pRHSOp)
{
    Complex invRHSOp;
    invRHSOp = pRHSOp.Invert();
    Mult(invRHSOp);
    return Mult(invRHSOp);
}

double Complex::GetImag()
{
    return mImag;
}


double Complex::GetReal()
{
    return mReal;
}

void Complex::Init(double pInitReal, double pInitImag)
{
    SetReal(pInitReal);
    SetImag(pInitImag);
}


Complex Complex::Invert()
{
    double denom = GetReal() * GetReal() + GetImag() * GetImag();
    double invReal = GetReal() / denom;
    double invImag = -GetImag() / denom;
    Complex inv;
    inv.Complex::Complex(invReal, invImag);
    return inv;
}


Complex Complex::Mult(Complex& pRHSOp)
{
    double prodReal = GetReal() * pRHSOp.GetReal() - GetImag() * pRHSOp.GetImag();
    double prodImag = GetImag() * pRHSOp.GetReal() + GetReal() * pRHSOp.GetImag();
    Complex product;
    product.Complex::Complex(prodReal, prodImag);
    return product;
}


Complex Complex::Negate()
{
    Complex neg;
    neg.Complex::Complex(-GetReal(), -GetImag());
    return neg;
}


void Complex::SetImag(double pNewImag)
{
    mImag = pNewImag;
}


void Complex::SetReal(double pNewReal)
{
    mReal = pNewReal;
}


Complex Complex::Sub(Complex& pRHSOp)
{
    Complex negRHSOp = pRHSOp.Negate();
    Complex diff = Add(negRHSOp);
    return diff;
}

string Complex::ToString()
{
    stringstream strstr;
    strstr << fixed << setprecision(4);
    strstr << "(" << GetReal();
    double imag = GetImag();
    if (imag < 0)
    {
        strstr << " - " << -imag << 'i';
    }
    else if (imag > 0)
    {
        strstr << " + " << imag << 'i';
    }
    strstr << ")";
    strstr.str();
    return strstr.str();
}
ComplexTest.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef COMPLEXTEST_HPP
#define COMPLEXTEST_HPP

#include "Complex.hpp"

class ComplexTest 
{
public:
	ComplexTest();
	void Run();
};

#endif 
ComplexTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <fstream> 
#include "Complex.hpp"
#include "ComplexTest.hpp"

using namespace std;

ComplexTest::ComplexTest()
{
}

void ComplexTest::Run()
{
    ifstream fin;
    fin.open("complex-in.txt");
    ofstream fout;
    fout.open("complex-out.txt");
    char operation;
    while (fin >> operation)
    {
        double real1, imag1, real2, imag2;
        fin >> real1;
        fin >> imag1;
        fin >> real2;
        fin >> imag2;
        Complex c1;
        c1.Complex::Complex(real1, imag1);
        Complex c2;
        c2.Complex::Complex(real2, imag2);
        Complex result;
        result.Complex::Complex();
        if (operation = '+')
        {
            result = c1.Add(c2);
        }
        else if (operation = '-')
        {
            result = c1.Sub(c2);
        }
        else if (operation = '*')
        {
            result = c1.Mult(c2);
        }
        else
        {
            result = c1.Div(c2);
        }
        fout << c1.ToString() << ' ' << operation << ' ' << c2.ToString() << " = " << result.ToString() << endl;
    }
    fin.close();
    fout.close();
}
complex-in.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
+ 123.456789 567.897012 112.345678 6654.12345
- 123.456789 567.897012 112.345678 6654.12345
* 123.456789 567.897012 112.345678 6654.12345
/ 123.456789 567.897012 112.345678 6654.12345
+ -1 -2 -3 -4
- -1 -2 -3 -4
* -1 -2 -3 -4
/ -1 -2 -3 -4
+ 573.456 872.332 9000.0 -9000.0
- 573.456 872.332 9000.0 -9000.0
* 573.456 872.332 9000.0 -9000.0
/ 573.456 872.332 9000.0 -9000.0
+ 10 20 -10 20
- 10 20 -10 20
* 10 20 -10 20
/ 10 20 -10 20
Last edited on
> Somewhere you are forgetting a ";"
> it was expecting something different before the class.

`#include' just copy-paste. Check out `Complex.hpp' for a missing semicolon
Thank you, that was embarrassing.
Nevermind.
Last edited on
Well, it's tomorrow here :)

The problem is obviously inside main, right? You're extracting the right numbers, and the correct amount of numbers. Something must be wrong with your if statements.

Thank you, that was embarrassing.


Not compared to your problem now :)
Topic archived. No new replies allowed.