function_name could not be resolved

Hi!
I'm trying to call a function of another class and it is throwing an error: function_name could not be resolved (as in the line in bold)
this may be a really stupid question but its almost 6 hours and i cannot workaround it. A reply would really be helpful!


void CNavigationSystem::enterRoute()
{
cout << "Assigning Route" << endl;
CWaypoint obj;

addWaypoint(obj);

}

the function addWaypoint belongs to another class CRoute in another header file and the function is defenied as below:

void CRoute::addWaypoint(CWaypoint const& wp)
{
*m_pWaypoint = wp;
m_pWaypoint++;
m_maxWp++;
}

I also tried making CRoute the base class and the CNavigationSystem class the derived class and then I'm getting an error for circular inclusion something like this token inclusion has not been defined something like that.

Any quick solutions would really be appreciated as I'm running out of time for its completion :(
Last edited on
You need to add a variable to your class CNavigationSystem that has the type CRoute:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Route.hpp"
...
class CNavigationSystem
{
...
  CRoute m_Route;
};
...
void CNavigationSystem::enterRoute()
{
cout << "Assigning Route" << endl;
CWaypoint obj;

m_Route.addWaypoint(obj);

}
Well now it is throwing me an error CRoute does not name a type for the line CRoute m_Route. I have a #include "Route.h". Also, if i do a forward declaration i.e. class CRoute; then I'm having an error m_Route has an incomplete type. What should I do be doing next?
Also, if you could tell me if I'm correct in my understanding that we are using an object of CRoute to call addWaypoint because object of one class can only call its functions unless we have inheritance?
you need to show the header files. Otherwise I'm not able to tell what's going wrong.

As i understand it CRoute is a container that holds CWaypoint. That'd make sense. The way you implemented addWaypoint() doesn't look right. You just replace the content of m_pWaypoint instead of adding a value.
CNavigationSystem header:


#ifndef CNavigationSystem_H
#define CNavigationSystem_H

#include "CWaypoint.h"
#include "CRoute.h"

class CRoute;
class CNavigationSystem
{
private:
CRoute m_route;
void enterRoute();
public:
CNavigationSystem();
void run();

};

#endif

CRoute header:

/* Generated by Together */

#ifndef CROUTE_H
#define CROUTE_H

#include "CWaypoint.h"
#include "CNavigationSystem.h"

class CRoute
{
private:
CWaypoint* m_pWaypoint;
unsigned int m_maxWp;
unsigned int m_nextWp;
unsigned int m_maxPoi;


public:
CRoute(unsigned int maxWp=0, unsigned int maxPoi=0);
void addWaypoint (CWaypoint const& wp);
void print();
};
#endif //CROUTE_H

CWaypoint header:

#ifndef CWaypoint_H
#define CWaypoint_H

#include <string>

using namespace std;


#define DEGREE 1
#define MMSS 2
#define SHOWADDRESS
#define PI 3.14159

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&);
};

#endif

CWaypoint was a project i did before and reusing it in this one..
There's no reason for CRoute header to #include "CNavigationSystem.h" .
Remove that line

Oh, and
Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
Thanks and sorry for not using the tags.
Topic archived. No new replies allowed.