1.11M Members

Error C2061 in visual studio

 
0
 

I try to reference a struct from another class in my code and it gives me an error, saying I have a syntax problem.

//Figure index
struct FIGURE_TYPE {
    //Where to crop the image from
    SDL_Rect crop;
    int x;
    int y;
};

That's the struct in Figure.h,

void set_camera ( SDL_Rect& camera, Figure::FIGURE_TYPE figure_index[FIGURE_COUNT] );

And that is where I reference it, from another header file called UI.h. I know there is a problem with referencing structures, I just don't know how to fix it. Simple problem, any one wanna help?

 
0
 

Making your FIGURE_TYPE struct from your Figure class public can solve your problem. Presumably your FIGURE_TYPE is in the defauls private block of your class, which means you can't access it directly. Making it public allows other classes to use that struct, even if it's declared in the Figure class.
Here's a small example:

#include <iostream>
using namespace std;
#define NR 5

class SDL_Rect{};
class A{
public:
    struct FIGURE_TYPE {
        SDL_Rect crop;
        int x;
        int y;
    };
};

class B{
public:
    void printFig(A::FIGURE_TYPE figure_index[NR]){
        for (int i=0;i<NR;i++){
            cout<<"X: "<<figure_index[i].x<<" Y: "<<figure_index[i].y<<endl;
        }
    }
};

int main(){
    A::FIGURE_TYPE figs[NR];
    for (int i=0;i<NR;i++){
        figs[i].x=i+10;
        figs[i].y=i+20;
    }
    B().printFig(figs);
    return 0;
}
 
0
 

It is public. Any other ideas?

Thank you for taking an interest, by the way.

 
0
 

This might be basic, but have you included UI.h in the current file?

 
0
 

It turns out I had a circular dependency with my headers. Thank you for helping though!

 
0
 

Solved

Question Answered as of 1 Year Ago by Suzie999 and Lucaci Andrew
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article