K
ks
Hi,
I have a problem with a piece of code. I'm in a situation where I have
to compile code using 2 different g++ compilers (2.95 and 4.12). I've
reduced the issue to a small, self contained program (given below)
//-------------------------------------
START----------------------------
#include <stdio.h>
struct A {
int a;
int b;
} ;
namespace NS {
void func(struct A *, int);
}
void NS::func(struct A * a_ptr, int i)
{
printf("%ld %d\n", a_ptr, i);
return;
}
namespace NS {
struct A : public ::A {} ;
}
struct NS::A* get_A(void)
{
return (struct NS::A *) 0;
}
int main()
{
func(get_A(), 1);
}
//--------------------------------
END----------------------------------
This program compiles on g++ 4.12 but fails on g++ 2.95 with the
following error:
test.cpp: In function `int main()':
test.cpp:30: implicit declaration of function `int func(...)'
If I change the call from func(...) to NS::func(...), both the
compilers are happy. I can understand the reason for that. However,
how does the g++ 4.12 compiler build without explicitly specifying the
namespace?
Which is the correct behavior?
Thanks
SK
I have a problem with a piece of code. I'm in a situation where I have
to compile code using 2 different g++ compilers (2.95 and 4.12). I've
reduced the issue to a small, self contained program (given below)
//-------------------------------------
START----------------------------
#include <stdio.h>
struct A {
int a;
int b;
} ;
namespace NS {
void func(struct A *, int);
}
void NS::func(struct A * a_ptr, int i)
{
printf("%ld %d\n", a_ptr, i);
return;
}
namespace NS {
struct A : public ::A {} ;
}
struct NS::A* get_A(void)
{
return (struct NS::A *) 0;
}
int main()
{
func(get_A(), 1);
}
//--------------------------------
END----------------------------------
This program compiles on g++ 4.12 but fails on g++ 2.95 with the
following error:
test.cpp: In function `int main()':
test.cpp:30: implicit declaration of function `int func(...)'
If I change the call from func(...) to NS::func(...), both the
compilers are happy. I can understand the reason for that. However,
how does the g++ 4.12 compiler build without explicitly specifying the
namespace?
Which is the correct behavior?
Thanks
SK