我在声明模板类型时遇到了很大困难,如下所示.
#include <cstdlib>
#include <iostream>
using namespace std;
template <class T>
class Foo
{
typedef T Bar;
};
template <class T>
typedef typename Foo<T>::Bar Bar;
int main(int argc, char *argv[])
{
Bar bar;
Foo<int> foo;
system("PAUSE");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误
template declaration of `typedef typename Foo<T>::Bar Bar'
Run Code Online (Sandbox Code Playgroud)
关于线
template <class T>
typedef typename Foo<T>::Bar Bar;
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我想避免在我的代码中写入typename Foo :: Bar.
我究竟做错了什么?
我有一个带有SVG的网页.在某些形状上,我需要显示工具提示.但是,我无法将工具提示显示在它应该的位置,只是距离形状本身一些像素.
它出现在屏幕的右侧,可能距离大约300px.我用来获取坐标的代码如下:
d3.select("body")
.select("svg")
.select("g")
.selectAll("circle")
.on("mouseover", function(){return tooltip.style("visibility", "visible");})
.on("mousemove", function(){
var svgPos = $('svg').offset(),
/*** Tooltip ***/
//This should be the correct one, but is displaying at all working at all.
/*x = svgPos.left + d3.event.target.cx.animVal.value,
y = svgPos.top + d3.event.target.cy.animVal.value;*/
//This displays a tool tip but way much to the left of the screen.
x = svgPos.left + d3.event.target.cx.animVal.value,
y = svgPos.top + d3.event.target.cy.animVal.value;
Tooltip
window.alert("svgPos: "+svgPos+" top: "+y+"px left: "+x+"px "+d3.event.target.cx.animVal.value);
return tooltip.style("top", x+"px").style("left",y+"px");
})
.on("mouseout", …
Run Code Online (Sandbox Code Playgroud) 我有一个客户端 - 服务器应用程序.
客户端使用两个不同的send()
调用发送一个字符串,后跟一个整数.这两个数据应该存储在服务器上的两个不同变量中.
问题是发送的两个变量都是在recv()
通话中接收的.因此,由两个不同的send()
s 发送的两个字符串被链接并存储在第一个的缓冲区中recv()
.
server.c:
printf("Incoming connection from client %s:%i accepted\n",inet_ntoa(clientSocketAddress.sin_addr),ntohs(clientSocketAddress.sin_port));
memset(buffer,0,sizeof(buffer));
int sizeofMessage;
if ((recv(clientSocket,buffer,MAXBUFFERSIZE,0)==sizeofMessage)<0)
{
printf("recv failed.");
closesocket(serverSocket);
clearWinsock();
return EXIT_FAILURE;
}
char* Name=buffer;
printf("Name: %s\n",Name);
if ((recv(clientSocket,buffer,MAXBUFFERSIZE,0))<0)
{
printf("bind failed.");
closesocket(serverSocket);
clearWinsock();
return EXIT_FAILURE;
}
int integer=ntohs(atoi(buffer));
printf("integer: %i\n",intero);
Run Code Online (Sandbox Code Playgroud)
client.c:
if (send(clientSocket,Name,strlen(Name),0)!=strlen(Name))
{
printf("send failed");
closesocket(clientSocket);
clearWinsock();
return EXIT_FAILURE;
}
printf("client send: %s",Name);
int age=35;
itoa(htons(age),buffer,10);
sizeofBuffer=strlen(buffer);
if (send(clientSocket,buffer,sizeofBuffer,0)!=sizeofBuffer)
{
printf("bind failed.");
closesocket(clientSocket);
clearWinsock();
return EXIT_FAILURE;
} …
Run Code Online (Sandbox Code Playgroud)