在C ++中的命名空间中使用函数名?

时间:2018-06-15 11:09:58

标签: c++

我想在命名空间系统中创建一个类Console。我这样定义了这个类:

声明

#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;
}

但编译器拒绝定义此类,因为系统已在stdlib.h中定义(包含在iostream中)。

我是否有一个解决方案来强制编译器&#34;忽略&#34;系统的第一个定义?

谢谢。

燕姿

1 个答案:

答案 0 :(得分:5)

上层命名空间名称应该是合理唯一的(而不是通用的),不仅与标准库冲突,而且还与其余的库冲突。所以只需将名称空间import { Component } from '@angular/core'; import { icon,latLng, marker, polyline, tileLayer,Map, point } from 'leaflet'; /*import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';*/ import * as L from 'leaflet'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { latlng:any public onMapReady(map: Map) { map.locate({setView: true, maxZoom: 16}); /*map.on('click', <LeafletMouseEvent>(e) => { alert(e.latlng.lat); alert(e.latlng.lng); });*/ var Icon = L.icon({ iconUrl: 'leaflet/marker-icon.png', shadowUrl: 'leaflet/marker-shadow.png', iconSize: [25,41], // size of the icon iconAnchor: [ 13, 41 ], // point of the icon which will correspond to marker's location shadowAnchor: [4, 62], // the same for the shadow popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor }); function onLocationFound(e) { var radius = e.accuracy / 2; let marker = new L.Marker(e.latlng, { draggable: true, icon: Icon }).bindPopup(""+e.latlng);; map.addLayer(marker); this.latlng = e.latlng } map.on('locationfound', onLocationFound); } // Define our base layers so we can reference them multiple times googleMaps = tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', { maxZoom: 20, subdomains: ['mt0', 'mt1', 'mt2', 'mt3'], detectRetina: true }); googleHybrid = tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', { maxZoom: 20, subdomains: ['mt0', 'mt1', 'mt2', 'mt3'], detectRetina: true }); // Marker for the top of Mt. Ranier summit = marker([ 46.8523, -121.7603 ], { icon: icon({ iconSize: [ 25, 41 ], iconAnchor: [ 13, 41 ], iconUrl: 'leaflet/marker-icon.png', shadowUrl: 'leaflet/marker-shadow.png' }) }); // Layers control object with our two base layers and the three overlay layers layersControl = { baseLayers: { 'Google Maps': this.googleMaps, 'Google Hybrid': this.googleHybrid, }, } /* overlays: { 'Mt. Rainier Summit': this.summit, 'Mt. Rainier Paradise Start': this.paradise, 'Mt. Rainier Climb Route': this.route } */ // Set the initial set of displayed layers (we could also use the leafletLayers input binding for this) options = { layers: [this.googleMaps] }; };放入另一个名称空间或将其重命名为

system

此外,您可能希望使用某种特定于命名空间名称的前缀。例如namespace stefv::system {