Reputation: 439
iI would like to create a class Console in a namespace system. I defined the class like that:
#pragma once
namespace system
{
class Console
{
public:
~Console();
void static writeLine();
private:
Console();
};
}
#include "Console.h"
#include <iostream>
system::Console::Console() {}
system::Console::~Console() {}
void system::Console::writeLine() {
std::cout << "test" << std::endl;
}
But the compiler is refusing to define this class because system is already defined in stdlib.h (included with iostream).
Do I have a solution to force the compiler to "ignore" the first definition of system ?
Thank you.
Stef
Upvotes: 0
Views: 67
Reputation: 37597
upper level namespace names should be reasonably unique (instead of being generic) and not clash not only with standard library but also with the rest of libraries out there. So just put namespace system
into another namespace or rename it to something like
namespace stefv::system
{
Additionally you may want to use some sort of prefix specific for namespace names. For example ns_stefv::ns_system
.
Upvotes: 5