我正在尝试将一些C ++转换为C#以用于个人学习项目。
下面你将看到我的C ++,然后尝试使用像Vector3这样的Unity类将其转换为C#。
我的问题:
如何在同一类型的结构中处理指向结构的指针?
据我所知,这是不可能的(HexTri m_nbAB,m_nbBC,m_nbCA;)
我是否需要使用课程?
.h文件
HexTile::HexTile( Imath::V3f p ) :
m_vertPos( p )
{
m_terrain = HexTile::Terrain_DESERT;
m_nrm = p.normalize();
}
HexTri::HexTri( size_t a, size_t b, size_t c) :
m_hexA( a ), m_hexB( b ), m_hexC( c )
{
m_nbAB = NULL;
m_nbBC = NULL;
m_nbCA = NULL;
}
.cpp文件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct HexTile
{
private Vector3 _position;
public Vector3 Position
{
get
{
return _position;
}
set
{
_position = value;
}
}
private Vector3 _normal;
public Vector3 Normal
{
get
{
return _normal;
}
set
{
_normal = value;
}
}
enum terrain{
Terrain_WATER,
Terrain_DESERT,
Terrain_GRASSLAND,
Terrain_FOREST,
Terrain_MOUNTAIN
};
List<HexTri> hextri;
public HexTile( Vector3 position, Vector3 normal)
{
// Defaults
_position = new Vector3(0,0,0);
_normal = new Vector3(0,0,0);
hextri = new List<HexTri>();
// Initilize with value
Position = position;
Normal = normal;
}
}
public struct HexTri
{
private int _hexA;
public int HexA
{
get
{
return _hexA;
}
set
{
_hexA = value;
}
}
private int _hexB;
public int HexB
{
get
{
return _hexB;
}
set
{
_hexB = value;
}
}
private int _hexC;
public int HexC
{
get
{
return _hexC;
}
set
{
_hexC = value;
}
}
// Q1 No pointers, cant do this
HexTri m_nbAB, m_nbBC, m_nbCA; //??
public HexTri( int a, int b, int c)
{
// Defaults
_hexA = -1;//??
_hexB = -1;//??
_hexC = -1;//??
// Initilize with value
HexA = a;
HexB = b;
HexC = c;
}
}
到目前为止,这是我的C#转换
select
totals.the_comment_liked,
totals.tot_like,
totals.tot_dis,
like_or_dislike.value as this_users_vote
from
(
select
the_comment_liked,
sum(case when value = 1 then 1 else 0 end) as tot_like,
sum(case when value = 2 then 1 else 0 end) as tot_dis
from
like_dislike_comm
group by
the_comment_liked
) as totals
left outer join (
select
the_comment_liked,
value
from
like_dislike_comm
where
/* This value has to be dynamically inserted by your PHP,
OR you can make this a parameter in a stored procedure */
user_who_liked = 118
) as like_or_dislike on
totals.the_comment_liked = like_or_dislike.the_comment_liked
答案 0 :(得分:0)
我对此的看法:
您以正确的方式声明了3个HexTri类型的对象。
编辑以解决pinkfloydx33在评论中解释的观点:
如果您将HexTri声明为类而不是结构,则此C#此代码会使a
和b
&#34;指向&#34;对同一个对象:
HexTri a = new HexTri();
HexTri b = a;
在this answer中对C#中的类和结构之间的差异(它们与C ++中的类与结构中的结构不同)的一个很好的解释。