-1

I'm getting a weird C2535 Error when I run my code. It consists of a three main classes (summarized below). There are some circular dependencies between them but they are preceded by #pragma once macros and should not be created more than one time. The error is occuring on the line:

CVertex(POINT3D p) : nx(0), ny(0), nz(0), nw(0) {
                  CVertex(p.x, p.y, 0, 1);

where it says:

error C2535: CVertex::CVertex(void) : member function already defined or declared

This doesn't make sense. It should only be getting declared once since I'm using #pragma once guards! I've tried with ifndef guards too and it makes no difference.

Here is a summary of the code (the important parts)

    //structs.h

    #pragma once
    #include matrices.h

    typedef struct {
    LONG x;
    LONG y;
    LONG z;
    } POINT3D;

    typedef struct{
    ....
    Matrix4x4 matrixFour;
    ...
    } DeviceStructure;

This is my second file:

//matrices.h

#pragma once
#include structs.h

class CVertex {
     public:
       CVertex(POINT3D x, POINT3D y, POINT3D z) ..... ;
       CVertex(POINT3D p) : nx(0), ny(0), nz(0), nw(0) {
              CVertex(p.x, p.y, 0, 1);
    }

....
}

My third file:

//world.h

#pragma once
#include structs.h
#include matrices.h

.....
(uses stuff from the previous classes)
....
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • Make a real test case and you might already see the reason –  Feb 02 '14 at 14:18
  • @DieterLücking Can you be a little more specific? I already have a real case... – CodyBugstein Feb 02 '14 at 14:21
  • 1
    "This doesn't make sense. It should only be getting declared once". The compiler **is your friend**, and 99.99999999999999% of the times it reveals real errors that you humble human are writing. – Stephane Rolland Feb 02 '14 at 14:22
  • You are writing nonsensical code, calling a constructor as though it is a function. Not putting a semi-colon at the closing brace of a class is bad. Make it bad enough and the compiler starts generating undiagnosable messages. Write good code, one line at a time. – Hans Passant Feb 02 '14 at 14:23
  • 3
    Advise: keep implemenation in .cpp – cageman Feb 02 '14 at 14:24
  • You have circular includes, `matrices.h` includes `structs.h` which includes `matrices.h`. This will cause problems and `#pragma once` won't solve that. One of the two files has to be read first, and if each file requires the other file than prerequisites will be missing and it will lead to errors. Structure the code so that no circular includes are necessary; I don't know if this will solve your current issue, but it surely will make it more easy to understand what is going on. – sth Feb 02 '14 at 14:27
  • Thank you guys for the cryptic clues, but it's not very helpful. The code is written relatively well (i.e. no syntax errors, good compartmentalization, etc) except for the include issues, which I am not very well versed in. I was hoping someone could provide a clear diagnosis – CodyBugstein Feb 02 '14 at 14:28
  • 2
    @Imray do you mean that `CVertex(POINT3D p) : nx(0), ny(0), nz(0), nw(0) { CVertex(p.x, p.y, 0, 1); }` is good code ??? Hans told you that you use the constructor like a function, and cageman told you to keep implementation seperated in its own cpp file – Stephane Rolland Feb 02 '14 at 14:30
  • 1
    @Imray Hans also told you that you don't end your class and struct definition with a correct semi-colon. – Stephane Rolland Feb 02 '14 at 14:35
  • Consider this: It if was really good code, it just have compiled without problems. As you can see, your code has multiple important problems besides the include errors, which could be considered *minor* problems seeing the other mistakes. – Manu343726 Feb 02 '14 at 15:05

1 Answers1

1

I got around the problem by splitting up the structs.h file into separate files: Point3DStruct.h and DeviceStructure.h.

Now there is a need to have a circular dependency between structs.h and matrices.h.

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363