0

I have a structure declared in header and implemented in source. Source file can perform on my struct variable, but my main can't see it. Why ?

A.hpp

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>

class A {
public: 
    struct myStruct {
        int someInt;
    } myStructVar;

    void loadA();
};

A.cpp

#include "stdafx.h"
#include "A.h"

void A::loadA() {
    myStructVar.someInt = 10;
    std::cout << myStructVar.someInt << std::endl; // 10 OK
}

Main.cpp

#include "stdafx.h"
#include "A.h"

int _tmain(int argc, _TCHAR* argv[])
{
    A a;
    a.loadA();
    std::cout << myStructVar.someInt() << std::endl; // Error: identifier "myStructVar" is undefined
    system("PAUSE");
    return 0;
}

Error is is Main.cpp

Error: identifier "myStructVar" is undefined.

Thanks.

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
David Pham
  • 151
  • 1
  • 1
  • 15

1 Answers1

2

Change

std::cout << myStructVar.someInt() << std::endl;

To

std::cout << a.myStructVar.someInt << std::endl;