We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,445 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Error C2061 in visual studio

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?

3
Contributors
5
Replies
1 Day
Discussion Span
4 Months Ago
Last Updated
6
Views
Question
Answered
jim.hurley
Newbie Poster
4 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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;
}
Lucaci Andrew
Practically a Master Poster
692 posts since Jan 2012
Reputation Points: 108
Solved Threads: 98
Skill Endorsements: 13

It is public. Any other ideas?

Thank you for taking an interest, by the way.

jim.hurley
Newbie Poster
4 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

Suzie999
Posting Whiz
322 posts since Jul 2010
Reputation Points: 49
Solved Threads: 15
Skill Endorsements: 0

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

jim.hurley
Newbie Poster
4 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Solved

jim.hurley
Newbie Poster
4 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 4 Months Ago by Suzie999 and Lucaci Andrew

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0675 seconds using 2.67MB