由买买提看人间百态

topics

全部话题 - 话题: namespaces
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
c**********e
发帖数: 2007
1
来自主题: Programming版 - C++ Q14: unnamed namespace
namespace
{
isDigit(char cc);
}
Which one of the following statements is true regarding the sample code
above?
a) The function "IsDigit" can be referenced from all unnamed namespaces.
b) The function "IsDigit" can be referenced from any namespace with a name.
c) The function "IsDigit" can only be referenced within the compilation unit
.
d) The namespace definition is illegal because the namespace name is missing.
e) The definition if "IsDigit" is illegal because the function body is
missing.
s*****n
发帖数: 994
2
来自主题: JobHunting版 - c++ namespace求指教 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: sampsun (american river), 信区: Programming
标 题: c++ namespace求指教
发信站: BBS 未名空间站 (Thu Feb 28 14:05:33 2013, 美东)
情况是这样的,我的程序要用到另外一个tool的class和class functions
但是我的程序和那个tool有相同的class名称(内容当然不一样)
譬如说这个class是Tree,我的source fils里面有这个class,要包含的tool里面也有
src_mine/my_tree.cpp
src_mine/main.cpp
...
src_tool/tool_tree.cpp
...
那我要用namespace的话,怎么用?是不是要在src_tool下面的每个文件都加上
namespace tool{} ?
以前没用过namespace,在这种情况下怎么用最方便?
d****p
发帖数: 685
3
If namespace name is too long, like
use namespace this_is_really_a_long_namespace;
use shorthand form
namespace this_is_really_a_long_namespace = now_short;
I even suggest more aggressive form: always qualify each namespace entity
individually. In collaborative dev environment, this minimizes the chance
your code collides with some unknowns.
b***i
发帖数: 3043
4
来自主题: Programming版 - how to export a class in a namespace in DLL?
我猜,你不加reference可以编译是因为你没有显式写构造函数。但是不写构造函数,有没有namespace没什么不同,同样可以编译运行,用好include, using namespace就行。你如果写了构造函数,尽管没有namesapce,没有reference仍然会报同样的错。
加了reference(当然应该要加),就可以有正常的构造函数,而这种情况,有没有namespace也没什么大的不同,用好include, using namespace就行。
写visual studio的dll, 必须(或者说,推荐)把所有事情都做对,参考
http://www.mitbbs.com/article_t/Programming/31216231.html
l******9
发帖数: 579
5
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: biuld error of C# reference of namespace in two projects
发信站: BBS 未名空间站 (Tue Jul 15 21:35:45 2014, 美东)
I am doing C# programming on Visual Studio 2013 win 7.
in project 1 :
using test.name.abc; // error: type or namespace "test" cannot be found.
public class testName2 : testName1 // build error here
{
public int id;
}
in project 2 :
namespace test.name.abc
{
public class testName1
{
public int dd;
... 阅读全帖
l******9
发帖数: 579
6
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: biuld error of C# reference of namespace in two projects
发信站: BBS 未名空间站 (Tue Jul 15 21:35:45 2014, 美东)
I am doing C# programming on Visual Studio 2013 win 7.
in project 1 :
using test.name.abc; // error: type or namespace "test" cannot be found.
public class testName2 : testName1 // build error here
{
public int id;
}
in project 2 :
namespace test.name.abc
{
public class testName1
{
public int dd;
... 阅读全帖
l******9
发帖数: 579
7
I am doing C# programming on Visual Studio 2013 win 7.
in project 1 :
using test.name.abc; // error: type or namespace "test" cannot be found.
public class testName2 : testName1 // build error here
{
public int id;
}
in project 2 :
namespace test.name.abc
{
public class testName1
{
public int dd;
}
}
I have added reference of dll file generated from project2 in project1. I
also made the build dependence as project1 depends on project2.
But, I always got build erro... 阅读全帖
r*******y
发帖数: 1081
8
来自主题: Programming版 - namespace defined in another file
How to use a namespace defined in another file without include ?
for example:
//1.cpp
namespace cc{int i = 10;}
//2.cpp
#include
int main(){
std::cout << cc::i < }
then compile: g++ -o 2 2.cpp 1.cpp
but error: cc has not been defined.
which directive should be added in 2.cpp? for example "extern namespace cc".
I tried but failed too.
Thanks
M**********n
发帖数: 432
9
来自主题: Programming版 - about namespace
If you don't use the std namespace, the compiler will assume the global
namespace. But cout is defined in the std namespace.
A**u
发帖数: 2458
10
来自主题: Programming版 - namespace 问题
#include
#include
using namespace std;
namespace S{
class A{
};
void swap(const A& x, const A& y){
std::cout << "A swap" << std::endl;
}
}
int main()
{
S::A x;
S::A y;
swap(x,y);
//S::swap(x,y);
std::cout << "fishing" << std::endl;
return 0;
}
这个code里, namespace S里的 swap 比 std里的swap specific
为啥 gcc 编译后,调用std版本呢
d******3
发帖数: 70
11
The purpose of namespaces is to avoid name clash. It seems Koenig Lookup
mixes up the names and defeats the very purpose of namespace. Why do we
need Koenig Lookup? This video explains the rationale of Koenig and
introduce a principle of namespace design.
http://www.youtube.com/watch?v=ZBK7aZ8v6vE
s*****n
发帖数: 994
12
来自主题: Programming版 - c++ namespace求指教
情况是这样的,我的程序要用到另外一个tool的class和class functions
但是我的程序和那个tool有相同的class名称(内容当然不一样)
譬如说这个class是Tree,我的source fils里面有这个class,要包含的tool里面也有
src_mine/my_tree.cpp
src_mine/main.cpp
...
src_tool/tool_tree.cpp
...
那我要用namespace的话,怎么用?是不是要在src_tool下面的每个文件都加上
namespace tool{} ?
以前没用过namespace,在这种情况下怎么用最方便?
p****e
发帖数: 3548
13
来自主题: JobHunting版 - c++ namespace求指教 (转载)
src_mine/my_tree.cpp
src_tool/tool_tree.cpp
现在你不是两个tree类冲突么
对tool的那个tree.cpp你可以用
namespace tool{
#include"tool_tree.cpp"
}
所有那个文件的声明都会被包含在tool的namespace里面
要调用就用tool::tree
m*****j
发帖数: 499
14
【 以下文字转载自 XML 讨论区 】
发信人: mickytj (MagicMicky), 信区: XML
标 题: eclipse 不认 namespace 吗?
发信站: BBS 未名空间站 (Thu May 19 14:32:45 2011, 美东)
eclipse似乎把这个namespace的声明当成element的属性了,还提示应该在dtd里声明这
个属性。这个是正常的吗?
h*****g
发帖数: 944
15
【 以下文字转载自 JobHunting 讨论区 】
发信人: huasing (Menlo Park), 信区: JobHunting
标 题: 怎么才能避免每次都写using namespace std
发信站: BBS 未名空间站 (Thu Jul 22 20:21:21 2010, 美东)
俺是新手,以前搞 java
现在写c++, 每个文件里都要写
using namespace std;
g++ compiler怎么设置一下,每次就不用写这么一行了?我用unix
c**********e
发帖数: 2007
16
来自主题: Programming版 - C++ Q07: unnamed namespace
namespace { int i; }
Which statement about the sample code above is true?
a) "i" has external linkage.
b) The code is equivalent to: static int i;.
c) "i" is visible to other compilation units.
d) "i" is only visible within the namespace.
r*******y
发帖数: 1081
17
来自主题: Programming版 - about namespace
//1.cpp
#include
// using namespace std;
int main(){cout<<1;}
this file can not be compiled since cout is not declared in this scope.
I read the header file iostream and find a declare for cout:
extern ostream cout;
It seems cout is declared in the header file iostream, but
why we also need to write down
using namespace std; ?
thanks.
m***x
发帖数: 492
18
来自主题: Programming版 - how to export a class in a namespace in DLL?
Using VS2010, a class can be exported from DLL. the client can access it
without problem. when put it into a namespace, the client program has link
error: unsolved external objs...
Any idea? thanks
the dll header file is:
#pragma once
#ifndef ECONOMICS_API_DCL
#ifdef ECONOMICS_EXPORTS
#define ECONOMICS_API_DCL __declspec(dllexport)
#else
#define ECONOMICS_API_DCL __declspec(dllimport)
#endif
#endif
namespace Economics
{
class ECONOMICS_API_DCL InterestRate
{
publi... 阅读全帖
b***i
发帖数: 3043
19
来自主题: Programming版 - how to export a class in a namespace in DLL?
if you don't add the reference, you couldn't build even without using
namespace.
You said, it compiled without namespace, so you already added the reference.
i*****t
发帖数: 220
20
来自主题: XML版 - A simple question on namespace
Since the only purpuse of namespace is to distinguish the elements from the
other different kinds, may I use a URL which is wrong or does not exit at all
as namespace? Thanks.
h*****g
发帖数: 944
21
俺是新手,以前搞 java
现在写c++, 每个文件里都要写
using namespace std;
g++ compiler怎么设置一下,每次就不用写这么一行了?我用unix
g*******y
发帖数: 1930
22
btw, normally using whole namespace is non recommended...
i***1
发帖数: 95
23
using namespace std;
大概三秒钟,就敲一下吧。。。
p****e
发帖数: 3548
24
来自主题: JobHunting版 - c++ namespace求指教 (转载)
namespace newname{
#include<...>
}
R*****i
发帖数: 2126
25
错误信息跟您贴出来的code不大匹配, testName1明明是个Class, 怎么就变成了
namespace?
您既然在project1的reference里加了project2, 能不能在project1的references里,用
鼠标右键选project2, 并点击"View in Object Browser", 看看project2里究竟有神马
?
c**t
发帖数: 2744
26
来自主题: DotNet版 - 心得:use XPath (+namespace)
因为工作的需要,要parse非常复杂的xml.用donet来parse XML非常方便,尤其用XPath
直接选取node(s)。但是当xml比较复杂的时候,比如从crystal reports直接导出的xml
,通常的办法:
XmlDocument xml = new XmlDocument();
xml.Load( PathToXmlFile );
XmlNodeList selection = xml.SelectNodes(strXPathExpression);
就行不通:明明xml.innerXml不空,selection.Count总是0。去
掉namespace就可以了。经过一番Google,终于找到答案:在SelectNodes前加上
XmlNamespaceManager nsmgr = new XmlNamespanceManager(xml.NameTable);
nsmgr.AddNamespace("a", "http://....");
nsmgr.AddNamespace("b", "urn:....");
XmlNodeList selection =
c**t
发帖数: 2744
27
来自主题: DotNet版 - 心得:use XPath (+namespace)
用Linq也许要加上namespace:
XNamespace ns = "urn:crystal-reports:schema";
var records = from r in xml.Document.Descendants(ns+"NameTag") select r;
...
p***p
发帖数: 559
28
I got a error "java.lang.LinkageError: loader constraints violated when
linking javax/xml/namespace/QName class" --
m*****j
发帖数: 499
29
今天搞了一个Web service,可是客户端死活连不上,最后灵光乍现,发现原来是两边的
namespace一个写的是http://xxx/ 一个写的是http://xxx
发个帖子提醒一下像我一样的菜鸟,细节害死人啊
然后顺便请教一下最后这个/到底该有还是没有呢?大致google了一下感觉似乎有没有都
行,只要保证两边一样就好了?
多谢先~ 顺祝大家happy easter~
f********f
发帖数: 290
30
我一般就是一个
using namespace std;就完事了
看很多人习惯于用一个,加一个:using std::vector; using std::cin;....
难不成效率高??
thanks a lot
r****t
发帖数: 10904
31
来自主题: Programming版 - C++ namespace 弱问
有这么一段 code,
#define NO_EXCEPTIONS
namespace MyNamespace {
class Location
{
public:
Location(const char *name);
Location() NO_EXCEPTIONS;
Location(const Location &);
Location & operator=(const Location & loc);
template
void read(const char *dataset_name, T & matrix) const {
MyNamespace::read(*this, dataset_name, matrix); //<<<<<< ERROR!
// Refer it to a non-member function
// so it can be overloaded even for classes
//
r****t
发帖数: 10904
32
来自主题: Programming版 - C++ namespace 弱问
我那办法不顶用,我在别的地方想要 override mynamespace::read, 就出现错误
error: redefinition of ‘template void mynamespace::read(hid_....
I think I only decleard it, not define it, but I need to check...
那怎么老 gcc 就可以?这段本意是定义个 namespace, 里面 reference 到一个还没
declare 的 member function, 然后用户写程序根据需要来实现这个 member function
, 这在 gcc-2.95 work, 现在就不能用了,那么现在是怎么处理这种问题的呢?总不至
于都是用 subclass + virtual 吧?
b***y
发帖数: 2799
33
来自主题: Programming版 - [合集] C++ namespace
☆─────────────────────────────────────☆
catbert (mimi) 于 (Tue Sep 27 16:15:22 2005) 提到:
Does it make sense to always use namespace, instead of the conventional way of
declaring varibles? Thanks.
☆─────────────────────────────────────☆
tuling (耕耘) 于 (Wed Sep 28 02:54:25 2005) 提到:
use anonymous name space would work in many cases.

of
以下是附件内容:
f********f
发帖数: 475
34
第一次用Visual Studio .net 2005, 需要将一个算法程序从C变成C++. 其实就是很小
的改动, 原来是两个global的functions, 现在我将他们放到一个class里变成两个
static functins. 但是编译的时候告诉我
error C2061: syntax error : identifier 'class'
好象是不认识class这个identifier. 试了一下namespace, 也不认识, 怎么回事呢? 谢谢!
k*******d
发帖数: 1340
35
我记得某本书上连using namespace std都不建议,建议的是用到什么写什么using std
d****p
发帖数: 685
36
Good catch.
Actually I have never used namespace alias - I love typing long names :-)
E*U
发帖数: 2028
37
来自主题: Programming版 - C++ Q07: unnamed namespace
en. I am puzzled
Internal linkage
The following kinds of identifiers have internal linkage:
* Objects, references, or functions explicitly declared static
* Objects or references declared in namespace scope (or global scope in
C) with the specifier const and neither explicitly declared extern, nor
previously declared to have external linkage
* Data members of an anonymous union
* C++ Function templates explicitly declared static
* C++ Identifiers declared in the unnamed names
E*U
发帖数: 2028
38
来自主题: Programming版 - C++ Q07: unnamed namespace
from another place
Note that using static for internal linkage is deprecated since it can't be
used on classes and you should use anonymous namespaces which although they
have external linkage are unreachable from other translation units.

in
k*******d
发帖数: 701
39
来自主题: Programming版 - C++ Q07: unnamed namespace
经测试b是正确的
#include
namespace {int i;}
void f(){i++;
std::cout<<"i in f:"< }
int main(){
f();
i++;
std::cout<<"i in main:"< }
输出结果为
i in f:1
in in main:2
c**********e
发帖数: 2007
40
来自主题: Programming版 - C++ Q07: unnamed namespace
Thank you guys for the discussion. evu and decamp are right, based on the
given answer. Testing is a good way for exploration. But some times (like this example) it does not tell the correct answer. Sometimes, testing is not exhaustive. In a compiling system I use, sometimes it gives results inconsistent to the Standard.
This question is intended to illustrate the use of anonymous namespaces.
Here, the wrong answers have as much exposition value as the correct answer.

a) "i" has external link
X****r
发帖数: 3557
41
来自主题: Programming版 - namespace defined in another file
namespace cc {extern int i;}
z****e
发帖数: 2024
42
来自主题: Programming版 - namespace defined in another file
我的意思是,像using那样,一次把名字都开放,类似的extern声明有没有,一次性把
整个namespace里边的对象都声明作为extern的?感觉是必须一个个单独声明的。
X****r
发帖数: 3557
43
来自主题: Programming版 - namespace defined in another file
编译器怎么知道这个namespace里有哪些对象呢?
那些对象定义的文件是在另一编译单元啊。
b***i
发帖数: 3043
44
来自主题: Programming版 - how to export a class in a namespace in DLL?
#include "interestrate.h"
using namespace Economics;
设置你的include 路径,能够正确找到interestrate.h
m***x
发帖数: 492
45
来自主题: Programming版 - how to export a class in a namespace in DLL?
without adding dll project as reference, the client compiled andrun well
without namespace.
if i deliver the dll, the client has no way to add project reference. that
is concern.
dont know what trick vs2010 made when
adding project reference.

reference.
h*******s
发帖数: 8454
46
来自主题: Programming版 - c++ namespace求指教
http://www.cplusplus.com/doc/tutorial/namespaces/
给tool那个加了就行了
但是按理说你自己的也应该加
n***e
发帖数: 723
47
来自主题: Programming版 - Visual Studio里C#的缺省namespace怎么改
或者你可以到solution explorer,点project里面,到property tab里面,application
页,有default namespace可选。
m********5
发帖数: 17667
48
来自主题: Programming版 - C++ namespace太混乱了
namespace好用啊
a*****a
发帖数: 438
49
来自主题: XML版 - A simple question on namespace
yes. for example, you can use urn:books for books namespace.
m*****j
发帖数: 499
50
来自主题: XML版 - eclipse 不认 namespace 吗?
eclipse似乎把这个namespace的声明当成element的属性了,还提示应该在dtd里声明这
个属性。这个是正常的吗?
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)