I am missing something obvious here.
Code:
#ifndef A_H
#define A_H
namespace outer
{
namespace inner
{
class A
{
private:
int aint;
public:
int getaint(void);
};
A a;
}
}
#endif // A_H
So I build a declaration and definition of "a", an object of type A in the outer::inner:: scope.
Code:
#include "a.h"
namespace outer
{
namespace inner
{
int A::getaint(void)
{
return aint;
}
}
}
Implement the method.
Code:
#include <iostream>
#include <string>
#include "a.h"
int main()
{
std::string x;
std::cout << outer::inner::a.getaint() << std::endl;
std::cin >> x;
return 0;
}
Run it.
No, it doesn't link.
LNK2005: "class outer::inner::A outer::inner::a" (?a@inner@outer@@3VA@12@A) already defined in prog.obj
It recognises the type of "a" which is instantiated in the header, yet it claims to find another instance of "a" somewhere. I wondered if it was taking the attempt to invoke the method as a definition rather then an action, but if that was the case, it would surely have created a typeless variable in the outer::inner:: namespace.