proxy Undefined type error

Hello everyone,
I have been working on this for two days. I've been Googling a lot and couldn't come up with an solution. Any help would be appreciated.

I got the following errors and don't know how I should fix:

Severity Code File Project Description Line
Error C2027 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy use of undefined type 'VaddV' 14
Severity Code File Project Description Line
Error (active) E0409 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy function "operator+" returns incomplete type "VaddV" 14

Severity Code File Project Description Line
Error C2679 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy binary '=': no operator found which takes a right-hand operand of type 'VaddV' (or there is no acceptable conversion) 14



class VaddV is a proxy and must not implement inside the class Vect2D.




Proxy.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
#include "Proxy.h"


class VaddV
{
public:
	const Vect2D& v1;
	const Vect2D& v2;
	VaddV(const VaddV& tmp) = default;
	VaddV& operator= (const VaddV&) = default;
	inline VaddV(const Vect2D& t1, const Vect2D& t2);
	operator Vect2D() {
		return Vect2D(v1.x + v2.x, v1.y + v2.y);

	}

	~VaddV() = default;



};

inline VaddV operator+(const Vect2D& a1, const Vect2D& a2)
{
	return VaddV(a1, a2);
}
inline VaddV::VaddV(const Vect2D& t1, const Vect2D& t2):
	v1(t1), v2(t2)
{

}



Proxy.h
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
#ifndef PROXY_H
#define PROXY_H
class Vect2D
{
public:
	Vect2D(const Vect2D& tmp) = default;
	Vect2D& operator =(const Vect2D& tmp) = default;
	Vect2D() = default;
	~Vect2D() = default;

	Vect2D(const float inX, const float inY);

	void setX(const float inX);
	void setY(const float inY);
	void set(const float inX, const float inY);

	float getX() const;
	float getY() const;


// -----------------------------------------------------------------------
// Rules: 
//  
//    No implementation in Header
//
// 
//    
//        Proxy is the only thing that can have the keyword "inline"
//            inline only for subsitution resolving.. that's it
//                No constructors or other operators... only proxy for substituion purpose
//   
//        No proxy implementation in header
//            conversion operator needs to be implemented in CPP file
//            proxy constructor are allowed in header (only exception)
// -----------------------------------------------------------------------

public:
	float x;
	float y;

};

class VaddV;
inline  VaddV operator+(const Vect2D& a1, const Vect2D& a2);

#endif 




ProxyTest.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Proxy.h"
int main()
{

	volatile float v1 = 2.0f;
	volatile float v2 = 3.0f;
	Vect2D A;
	A.set(0.0f, 0.0f);
	Vect2D B;
	B.setX(v1);
	B.setY(v2);
	Vect2D sum;
	sum.set(0.0f, 0.0f);
	sum = A + B;

}

// ---  End of File --------------- 

Last edited on
Passionate programmer wrote:

Hello everyone,
I have been working on this for two days. I've been Googling a lot and couldn't come up with an solution. Any help would be appreciated.

I got the following errors and don't know how I should fix:

Severity Code File Project Description Line
Error C2027 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy use of undefined type 'VaddV' 14

Severity Code File Project Description Line
Error (active) E0409 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy function "operator+" returns incomplete type "VaddV" 14

Severity Code File Project Description Line
Error C2679 C:\Users\PassionateProgrammer\Documents\Test\ProxyTest.cpp Proxy binary '=': no operator found which takes a right-hand operand of type 'VaddV' (or there is no acceptable conversion) 14


class VaddV is a proxy and must not implement inside the class Vect2D.

Proxy.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
#include "Proxy.h"


class VaddV
{
public:
	const Vect2D& v1;
	const Vect2D& v2;
	VaddV(const VaddV& tmp) = default;
	VaddV& operator= (const VaddV&) = default;
	inline VaddV(const Vect2D& t1, const Vect2D& t2);
	operator Vect2D() {
		return Vect2D(v1.x + v2.x, v1.y + v2.y);

	}

	~VaddV() = default;



};

inline VaddV operator+(const Vect2D& a1, const Vect2D& a2)
{
	return VaddV(a1, a2);
}
inline VaddV::VaddV(const Vect2D& t1, const Vect2D& t2):
	v1(t1), v2(t2)
{

}


Proxy.h
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
#ifndef PROXY_H
#define PROXY_H
class Vect2D
{
public:
	Vect2D(const Vect2D& tmp) = default;
	Vect2D& operator =(const Vect2D& tmp) = default;
	Vect2D() = default;
	~Vect2D() = default;

	Vect2D(const float inX, const float inY);

	void setX(const float inX);
	void setY(const float inY);
	void set(const float inX, const float inY);

	float getX() const;
	float getY() const;


// -----------------------------------------------------------------------
// Rules: 
//  
//    No implementation in Header
//
// 
//    
//        Proxy is the only thing that can have the keyword "inline"
//            inline only for subsitution resolving.. that's it
//                No constructors or other operators... only proxy for substituion purpose
//   
//        No proxy implementation in header
//            conversion operator needs to be implemented in CPP file
//            proxy constructor are allowed in header (only exception)
// -----------------------------------------------------------------------

public:
	float x;
	float y;

};

class VaddV;
inline  VaddV operator+(const Vect2D& a1, const Vect2D& a2);

#endif  


ProxyTest.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Proxy.h"
int main()
{

	volatile float v1 = 2.0f;
	volatile float v2 = 3.0f;
	Vect2D A;
	A.set(0.0f, 0.0f);
	Vect2D B;
	B.setX(v1);
	B.setY(v2);
	Vect2D sum;
	sum.set(0.0f, 0.0f);
	sum = A + B;

}

// ---  End of File --------------- 




Your operator+ returns a VaddV object. A forward declaration won't suffice for the declaration of this at line 44 of Proxy.h; the compiler needs to be able to see the VaddV definition for it to be able to understand this declaration.

The VaddV definition should go into Proxy.h for this to work.
Last edited on
Thank you so much. It helped a lot.
You're welcome! Glad I could help.
Topic archived. No new replies allowed.