SpiralTest.h
#ifndef SPIRALTEST_H_
#define SPIRALTEST_H_
namespace eveready
{
struct TNotes{
int pie;
void meth();
};
extern TNotes tell;
}
#endif /* SPIRALTEST_H_ */
SpiralTest.cpp
#include "SpiralTest.h"
namespace eveready
{
void TNotes::meth(){
pie=0;
}
}
now i am trying to access variable pie into abc.cpp
abc.cpp
#include "SpiralTest.h"
using namespace eveready;
tell.meth();
but it shows error when i compile (.text+0x49): undefined reference to `eveready::tell'
i tried also `eveready::tell.meth(); but again it shows same error. what should i do..?
structures are deprecated in C++. You are declaring tell as extern in SpiralTest.h which means compiler thinks it would be allocated storage somewhere else. So when it encounters tell in abc.cpp, the linker throws error.
1) Use class instead of structures. 2) define tell (maybe by constructor of TNotes class) in Spiraltest.cpp or abc.cpp