error: variable has initializer but incomplete type

Hi! I'm trying to have a class which is working fine with a dependency to another class which is also working fine but it is throwing an error : error: variable has initializer but incomplete type

the method i'm getting error in is:
1
2
3
4
5
6
7
8
9
10
11
12
CXMLString CWaypoint::toXML()
{
	CXMLString cxml_name(this->m_name,"Name");
	CXMLString cxml_lat(this->m_latitude,"Latitude");
	CXMLString cxml_lon(this->m_longitude,"Longitude");
	string structure;
	structure = "\n\t" + cxml_name + "\n\t" + cxml_lat + "\n\t" + cxml_lon + "\n";
	CXMLString ret(structure,"Waypoint");
	cout << "!!!" << ret << endl;
	return ret;

}


and in the header file for CWaypoint is:

#ifndef CWaypoint_H
#define CWaypoint_H

#include <string>
#include <stdlib.h>
#include <math.h>
#include "CXMLString.h"

using namespace std;


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
#define DEGREE 1
#define MMSS 2
//#define SHOWADDRESS
#define PI 3.14159

//forward declaration
class CXMLString;

class CWaypoint
{
private:
	double m_latitude, m_longitude;
	string m_name;

	void transformLongitude2degmmss(int&, int&, double&);
	void transformLatitude2degmmss(int&, int&, double&);

public:

	void set(string, double, double);
	CWaypoint(string = "", double lat=0, double lon=0);
	void print(int);
	string getName();
	double getLongitude();
	double getLatitude();
	void getAllDataByPointer(string*, double*, double*);
	void getAllDataByReference(string&, double&, double&);
	//function is of const so that a const object pass can call it (*less method*)
	double calculateDistance (CWaypoint const&) const;
	CWaypoint add (CWaypoint const&);
	bool less (CWaypoint const&);
	CXMLString toXML();
};

#endif 


can someone help what could be the possible reason for this. Also, I have given #include"CXMLString.h" wherever an object of CWaypoint is being used.
The error message usually names the variable that has incomplete type. So show the full error message.

I think that the problem is that the compiler does not see the full definition of CXMLString. You included only the declaration

class CXMLString;

but the compiler requires the definition.

Or it looks like the declaration

class CXMLString;

hides the previous declaration of the same class. It is possible if they are in different scopes.

Or some compilers distinguish class and struct keywords. Check what keyword the definition of CXMLString uses.
Last edited on
yeah sorry! it was in a different namespace.. included that and its working fine..
thanks!
Topic archived. No new replies allowed.