Code not recognizing my custom class (it seems)

Hello all. I'm relatively sure the problem I'm having can be fixed with a minor change in syntax somewhere (not sure what or where) but I just thought I would post it here in case anyone had any other ideas.

I have a PointManager class, which stores "Points." In this class, I have a method that basically checks whether each Point is the same subclass as it's neighbors. Here is said method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void PointManager::FindEdgesArcs()  // should work once ConnectorManager::AddConnector() is implemented.
{
    
    std::list<Point>::iterator second = PointList.begin(); // use two iterators for comparison purposes

    if ( second != PointList.end() ) // Treat empty list
        for(std::list<Point>::iterator first = second++; second != PointList.end(); ++first, ++second)
        {
            if((*first).GetType() == "edge" && (*second).GetType() == "edge") { _cManager.AddConnector(new Edge(&(*first), &(*second)));}
            else if((*first).GetType() == "edge" && (*second).GetType() == "arc") { _cManager.AddConnector(new Edge(&(*first), &(*second)));}
            else if((*first).GetType() == "arc" && (*second).GetType() == "arc") { _cManager.AddConnector(new Arc(&(*first), &(*second)));}
            else { std::cout << "Not enough points to make an edge or arc" << std::endl;}
        }
}


When I compile, everything is fine except I get the following error message:
"error: expected type-specifier before 'Arc'"

I don't get the error message for 'Edge,' even though both are subclasses of a class "Connector." Right now, 'Arc' and 'Edge' are basically the same class (need this working before I flesh them out).

Arc.h and Edge.h are both included in my ConnectorManager.h which is included in PointManager.h, so both should be included. Any ideas? Thanks for your help!
Arc is implemented in the .h or a .cpp? (Is Arc fully implemented?)


Arc : public Connector Edge : public Connector

ConnectorManager.h has
1
2
#include "Arc.h"
#include "Edge.h" 


PointManager.h The class in question has
#include "ConnectorManager.h"

And it looks like the contructors for both Edge and Arc are accepting Connector * as their parameters?
Last edited on
Arc is implemented in a .cpp, almost word for word the same as Edge.

Here are Arc.h and Edge.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
#ifndef ARC_H
#define ARC_H

#include "Connector.h"

struct CenterPoint
{
    float cX;
    float cY;
};

class Arc : public Connector
{
    public:
        Arc(Point * p1, Point * p2);

        void SetCenter(float x, float y);
        CenterPoint GetCenter() {return _center;};

    private:
        CenterPoint _center;
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef EDGE_H
#define EDGE_H

#include "Connector.h"

class Edge : public Connector
{
    public:
        Edge(Point * p1, Point * p2);
};

#endif


ConnectorManager.h does include both of those. and PointManager.h includes ConnectorManager.h

Arc and Edge both take "Point"s as their parameters. Is that enough info?
And without the new Arc(), there are no compile errors?

If you copy and pasted your code it looks like you are missing a closing } after your second conditional statement...

Here:
else if((*first).GetType() == "edge" && (*second).GetType() == "arc") { _cManager.AddConnector(new Edge(&(*first), &(*second)));

Maybe just a typo?
Last edited on
Correct.

Edit: Nah, I have that closing } in my code. Hmm...
Last edited on
I'm just going down the list of things I would check off when this happens to me...

1) So it looks like your includes are good, are you using any namespaces?
2) Silly... but, are the files actually added to your project?

...Thinking of others right now...
I am not using any namespaces in my project, as they usually screw me up rather than help.
Hah, I'm pretty sure the files are added but I will double check! Edit: Yeah, they're there :(
Last edited on
Ok, I don't know how I was supposed to figure this out, but apparently "Arc" is some sort of reserve word somewhere. I changed the class name to ArcC and now it compiles. -_-

Thank you for your help, clanmjc. It was good to go through this systematically with someone and know I wasn't just going crazy.
Last edited on
hehe, in this situation this is where a Namespace would help you and you can use Arc... if you so desired.
Ah! I see. Well that is good to know. I'm still pretty new at this, I will see if I can't finagle a Namespace in here somewhere.
Topic archived. No new replies allowed.