问题描述
我定义一个类。我想在CUDA的光线跟踪代码中添加一些纹理。而且我在调用构造函数时使用new。
#ifndef TEXTURE_H
#define TEXTURE_H
#include "RTnextweek.h"
#include "vec3.h"
class texture
{
public:
__device__ virtual vec3 value(float u,float v,const vec3 &p) const = 0;
};
class const_texture : public texture
{
public:
__device__ const_texture() {}
__device__ const_texture(vec3 c) : color(c) { }
__device__ virtual vec3 value(float u,const vec3 &p) const
{
return color;
}
public:
vec3 color;
};
class checker_texture : public texture
{
public:
__device__ checker_texture() {}
__device__ checker_texture(texture *t0,texture *t1) : even(t0),odd(t1) {}
__device__ virtual vec3 value(float u,const vec3 &p) const
{
float sines = sin(10 * p.x()) * sin(10 * p.y()) * sin(10 * p.z());
if (sines < 0)
return odd->value(u,v,p);
else
return even->value(u,p);
}
public:
texture *even;
texture *odd;
};
#endif
编译器报告:
nvcc main.cu -o texture.exe
main.cu
E:\texture.h(7): error: argument list for class template "texture" is
missing
E:\texture.h(14): error: argument list for class template "texture" is missing
......
11 errors detected in the compilation of "main.cu".
我什至没有定义模板,但是编译器报告模板错误。我的代码有什么问题?为什么会发生此问题?
解决方法
尽管记录不充分, Int32 port = int.Parse(TCPPort);
IPAddress localAddr = IPAddress.Parse(TCPHost);
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
TcpListener server = new TcpListener(localAddr,port);
server.Start();
while (true)
{
Console.WriteLine("Waiting for a connection...");
Console.WriteLine();
TcpClient client = new TcpClient();
client = server.AcceptTcpClient();
NetworkStream stream = client.GetStream();
string loggerTime = RequestTime(client,stream);
} ...
static string RequestTime(TcpClient client,NetworkStream stream)
{
// 0xF7 is hard coded here,this needs to find
byte[] sendData = { 0xF7,0x03,0x00,0x1F,0x02,0xE1,0x5B };
stream = client.GetStream();
stream.Write(sendData,sendData.Length);
Byte[] data = new Byte[9];
try
{
Int32 bytes = stream.Read(data,data.Length);
if (ValidateCRC(data,data.Length) && bytes != 0)
{
byte[] buf = new byte[] { data[3],data[4],data[5],data[6] };
buf.SwapBytes(0,1);
buf.SwapBytes(2,3);
Array.Reverse(buf,buf.Length);
string hexValue = ConvertBytesToHexa(buf);
int secondsAfterEpoch = Int32.Parse(hexValue,System.Globalization.NumberStyles.HexNumber);
DateTime epoch = new DateTime(1970,1,1);
DateTime loggerTime = epoch.AddSeconds(secondsAfterEpoch);
Console.WriteLine("Logger UTC Time: {0}",loggerTime.ToUniversalTime());
Console.WriteLine();
return loggerTime.ToUniversalTime().ToString();
}
else
{
Console.WriteLine("Response CRC is not matched for UTC Time");
return string.Empty;
}
}
catch (Exception ex)
{
}
}
是C ++运行时API的模板类(例如here)。它是在内部标头中定义的,该标头在nvcc的预处理阶段会自动包含在内。
如果将纹理类型重命名为其他类型,问题将消失。例如:
texture