Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
any.cpp
C++
#include <iostream>
namespace hey
{
	inline const int Obiick()
	{
		double pi{ 3.1416 };
		return 0;
	}
}


main.cpp
C++
#include <iostream>
inline const int Obiick();

int main()
{
	int B{ Obiick()};
	std::cout << B; 
	return 0;  
}

in the output, it is saying that pi is initialized but not referenced ( when I don't use namespace in the any.cpp file.
then when I use namespace and try to use hey::Obiick() , it gives me a different error.

What I have tried:

i have tried using namespace and without namespace for inline . but everytime I'm getting error. Im new here so .
Posted
Updated 24-Apr-22 12:45pm
v2

1 solution

There are multiple issues here.

* 'Pi' initialized but not referenced message
This is a warning, rather than an error. The compiler sees that you have declared a variable, but do not use it anywhere. Either delete the declaration or use the variable.

* Namespaces
You have declared 'inline const int Obiick();' before your main() function. This is in the global namespace, i.e. ::Obiik(). You then declare 'inline const int Obiik()' in the 'hey' namespace, i.e. hey::Obiik(). These are not the same function!

If you wish to declare a function inside a namespace, you should write:

namespace foo
{
int bar();
}

* inlining
You should declare 'inline' functions either in the same source file where they are used or in a header file common to all users of the inline function.

I hope that this helps!
 
Share this answer
 
v2
Comments
Obiick 25-Apr-22 16:01pm    
What I have found it, the namespace is making the code wrong and I fixed other thing that you have mention. I Just wanna know how can I link namespace? we know that we use ( :: ) this for linking it. but this is not working at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900