在c ++中使用模板时,我遇到了将typename T转换为string的问题.例如:
template <typename T>
class Matrix {
public:
Matrix() {
//my_type = string type of T. i.e. if T is char. I want my_type to be "char".
}
string my_type;
}
Run Code Online (Sandbox Code Playgroud)
如何将T转换为表示T是什么的字符串.
注意:我只是在玩耍,所以请不要担心什么时候需要这样的东西.
可能重复:
在终止进程之前保存gmon.out
我正在尝试在Linux环境中分析服务器(可用的源代码.c代码).该服务器像Web服务器一样连续运行.我正在尝试使用gprof来配置服务器.如果服务器自行退出,则会生成gmon.out文件.我可以使用gprof和gmon.out来理解配置文件数据.现在问题是,这台服务器正在连续运行,等待传入的套接字连接,请求等.如果我终止此服务器,则不会生成gmon.out.此时我看到以下选项.
编辑:服务器是多进程服务器.在FreeBSD 7.2上运行
我敢肯定,人们之前已经解决了这些问题.我没能在SO或外面找到有用的信息.
我感谢人们的任何想法/解决方案.
谢谢一堆.
更新1:
不知怎的,我设法为valgrind获得端口.当我运行make时,我得到以下错误.
=> valgrind-stable-352.tar.gz doesn't seem to exist in /usr/obj/ports/distfiles/.
=> Attempting to fetch from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/.
fetch: ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/valgrind-stable-352.tar.gz: File unavailable (e.g., file not found, no access)
=> Attempting to fetch from http://www.rabson.org/.
fetch: http://www.rabson.org/valgrind-stable-352.tar.gz: No address record
=> Couldn't fetch it - please try to retrieve this
=> port manually into /usr/obj/ports/distfiles/ and try again.
*** Error code 1
Run Code Online (Sandbox Code Playgroud)
我试图在网上找到valgrind-stable-352.tar.gz.我找到的所有链接都已死亡.
我在我的freebsd上安装了pstack,实现的pstack只提供堆栈跟踪.参考:http://sourceforge.net/projects/bsd-pstack/
我的理解是systemtap仅用于内核空间事件,仪器等. …
注意:有关重现此问题的所有代码,请访问https://gist.github.com/SrikanthRao/c9fc35e6fe22a74ab40c
http:// localhost:8080/date/bean?date = 2014-13-23 (使用BeanParam)生成"{"代码":500,"message":"处理您的请求时出错.它已被记录(ID 48be9aa43bd49547)."}"而没有将MultiExceptionMapper添加到泽西.
如果我将MultiExceptionMapper添加到jersey,则上面的url会导致
"日期不是YYYY-MM-DD格式或无效"
http:// localhost:8080/date?date = 2014-13-23(直接@QueryParam参数)生成"日期不是YYYY-MM-DD格式或无效"
几个问题:
这是请求时生成的堆栈跟踪(不将MultiExceptionMapper添加到jersey).当然删除了很长的痕迹.如果您需要完整的堆栈跟踪,请告诉我.
ERROR [2015-05-04 18:48:33,366] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 0f23e4de758653d6
! javax.ws.rs.WebApplicationException: HTTP 400 Bad Request
! at io.dropwizard.jersey.params.AbstractParam.<init>(AbstractParam.java:28) ~[dropwizard-jersey-0.8.1.jar:0.8.1]
! at com.fun.myapp.LocalDateTimeParam.<init>(LocalDateTimeParam.java:20) ~[classes/:na]
! at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_45]
...
...
Causing: org.glassfish.hk2.api.MultiException: A MultiException has 3 exceptions. They are:
! 1. javax.ws.rs.WebApplicationException: HTTP 400 Bad Request
! 2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.fun.myapp.PaginationFilters errors were found
! …Run Code Online (Sandbox Code Playgroud) 需要提示设计一个有效的算法,该算法采用以下输入并吐出以下输出.
输入:两个整数A和B的排序数组,每个长度为n
输出:一个排序数组,由数组A和B的笛卡尔积组成.
For Example:
Input:
A is 1, 3, 5
B is 4, 8, 10
here n is 3.
Output:
4, 8, 10, 12, 20, 24, 30, 40, 50
Run Code Online (Sandbox Code Playgroud)
以下是我尝试解决此问题的方法.
1)鉴于输出为n ^ 2,有效算法不能比O(n ^ 2)时间复杂度做得更好.
2)首先,我尝试了一种简单但效率低下的方法.生成A和B的笛卡尔积.它可以在O(n ^ 2)时间复杂度下完成.我们需要存储,所以我们可以对它进行排序.因此O(n ^ 2)空间复杂度也是如此.现在我们排序n ^ 2个元素,这些元素不能比O(n ^ 2logn)做得更好,而不对输入做任何假设.
最后我有O(n ^ 2logn)时间和O(n ^ 2)空间复杂度算法.
必须有一个更好的算法,因为我没有使用输入数组的排序性质.
请参阅以下代码以更好地理解我的问题.
class compareByValue {
public:
bool operator()(const string* s1, const string* s2) const
{
if (s1 == s2)
return true;
if ((s1==NULL) || (s2==NULL))
return false;
return (0 == s1->compare(s2->c_str()));
}
};
map<string*, string*, compareByValue> nodeIdToIpAddress;
for (int i = 0; i < nrec; ++i) {
nodeIdToIpAddress[ptr1[i]] = ptr2[i];
cout << "Added " << *(ptr1[i]) << " , " << *(ptr2[i]) << endl;
}
cout << "map has " << nodeIdToIpAddress.size() << " elements!" << endl;
Run Code Online (Sandbox Code Playgroud)
我有一个地图,维护键,值对,它们是指向字符串对象的指针.我确信键和值都不是NULL指针.当我运行上面的程序(好吧,我跳过周围的代码以使其更容易理解),"添加......"被打印49次.ptr1 [i],ptr2 [i]是字符串对象的指针,不是NULL指针,因为我的程序不会发生段错误.
我遇到的问题是,当我在最后打印地图的大小时,它表示地图中只有1个元素. …