Hello what would be the best way to return a pair<> via a structure Let me further explain. Below is the type of struct that I want to use:

//compass.h
struct Compass {
pair<int, int> C;
pair<int, int> E;
pair<int, int> W;
pair<int, int> NE;
pair<int, int> NW;
pair<int, int> SE;
};

Compass GetCompass()
{
C = make_pair(3,4);
bla bla bla
}

I would like to call C in my main file:

main()
{
V GetCompass();
J = V.C.first;
K = V.C.second;
}

What I would like to do is call this function and retrieve the value of C??? Any ideas??

You can return entire structures from functions.

Compass getCompass()
{
    Compass result;
    result.C = make_pair(3,4);
    // etc.
    return result;
}

void someFunction()
{
    Compass V = getCompass();
    int j = V.C.first;
    // ...
}
{

thank you I used your suggestion and it worked perfectly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.