I work in Visual Studio 2012. I am just trying to create structure with pointers to same structure:
namespace PLT_1_lab {
class Program {
struct tNode {
string oper;
int level;
tNode *left;
tNode *right;
}
}
}
And in lines with * i get error (I have translated VS so it can look a bit different):
Impossible to get address, define size of declare pointer to controlled type ("PLT_1_lab.Program.tNote")
Matthew's answer is probably the most appropriate way to go, but just to explain why the compiler is complaining...
From the C# 5 specification, section 18.2 (pointer types):
A pointer-type is written as an unmanaged-type or the keyword void, followed by a * token:
pointer-type: unmanaged-type * void * unmanaged-type: type
The type specified before the * in a pointer type is called the referent type of the pointer type. It represents the type of the variable to which a value of the pointer type points.
...
An unmanaged-type is any type that isn’t a reference-type or constructed type, and doesn’t contain reference-type or constructed type fields at any level of nesting. In other words, an unmanaged-type is one of the following:
- sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
- Any enum-type.
- Any pointer-type.
- Any user-defined struct-type that is not a constructed type and contains fields of unmanaged-types only.
The intuitive rule for mixing of pointers and references is that referents of references (objects) are permitted to contain pointers, but referents of pointers are not permitted to contain references.
So the problem here is that your tNode
struct contains a string
value. Without that - and assuming you're in an unsafe context - the code compiles.
See more on this question at Stackoverflow