Category : namespaces

In myfunction.h, I declare the function myFunction inside the namespace MyNamespace: namespace MyNamespace{ void myFunction(); } In myfunction.cpp, I include the implementation: #include "myfunction.h" void MyNamespace::myFunction(){ std::cout<<"My function"<<std::end; } Everything compiles fine. If instead in the .cpp, I write: using namespace MyNamespace; void myFunction(){ std::cout<<"My function"<<std::end; } I get an Undefined Symbol error during linking. ..

Read more

Take the following: foo.h #ifndef FOO_H #define FOO_H #include <stdint.h> enum directions { NORTH, EAST, SOUTH, WEST }; bool foo_a(uint16_t a); bool foo_b(enum directions a); #endif //FOO_H foo.cpp #include "foo.h" #include <iostream> namespace test { bool foo_a(uint16_t a) { return a < 22; } bool foo_b(enum directions a) { return a < WEST; } bool ..

Read more

The code below gives an error in the a::b::print function: Invalid operands to binary expression (‘std::ostream’ (aka ‘basic_ostream<char>’) and ‘Foo’). The error goes away if I comment out the operator<< overload in namespace b. But I don’t understand why that makes a difference because it has a different signature to the operator<< overload in namspace ..

Read more

In the code below, I get an error when trying to print time_point to the console. It goes away if I move operator<< outside of my_namespace. Why is this? Must I define my operator<< function in the global namespace? #include <iostream> #include <chrono> #include <date/date.h> namespace my_namespace { std::ostream &operator<<(std::ostream &os, const std::chrono::system_clock::time_point &time_point) { ..

Read more

The following code is from an idl generated class in Cyclonedds, modifying this code this is a generated class from idlpp generator of Cyclonedds following is a small code snippet, not the full generated code namespace DDSData { class RData OSPL_DDS_FINAL { public: int32_t rDataID_; int32_t rDataInt_; std::string rDataMessage_; DDSData::NestedData NestedStuct_; public: rData() : rDataID_(0), ..

Read more