D
Don Kim
I copied this example off ECMA C++/CLI draft document, and it doesn't
compile:
#using <mscorlib.dll>
using namespace System;
public ref class Stack {
public:
Stack() {
first = nullptr;
}
property bool Empty {
bool get() {
return (first == nullptr);
}
}
Object^ pop() {
if (first == nullptr)
throw gcnew Exception("Can't Pop from an empty Stack!");
else {
Object^ temp = first->Value;
first = first->Next;
return temp;
}
}
void Push(Object^ o) {
first = gcnew Node(o, first);
}
ref struct Node {
Node^ Next;
object^ Value;
Node(object^ value) : Node(value, nullptr) {}
Node(object^ value, Node^ next) {
Next = next;
Value = value;
}
};
private:
Node^ first;
};
int main()
{
Stack^ s = gcnew Stack();
for (int i = 0; i < 10; i++)
s->Push(i);
s = nullptr;
}
I get the following errors:
8_4.cpp
8_4.cpp(32) : error C2143: syntax error : missing ';' before '^'
8_4.cpp(32) : error C2501: 'Stack::Node:bject' : missing storage-class or
type specifiers
8_4.cpp(32) : error C2501: 'Stack::Node::Value' : missing storage-class or
type specifiers
8_4.cpp(33) : error C2143: syntax error : missing ')' before '^'
8_4.cpp(33) : error C2143: syntax error : missing ';' before '^'
8_4.cpp(33) : error C3149: 'Stack::Node' : cannot use this type here without
a top-level '^'
8_4.cpp(33) : error C2059: syntax error : ')'
8_4.cpp(33) : error C2065: 'value' : undeclared identifier
8_4.cpp(33) : fatal error C1903: unable to recover from previous error(s);
stopping compilation
I'm using .Net 2.0 Beta. Any clues?
-Don Kim
compile:
#using <mscorlib.dll>
using namespace System;
public ref class Stack {
public:
Stack() {
first = nullptr;
}
property bool Empty {
bool get() {
return (first == nullptr);
}
}
Object^ pop() {
if (first == nullptr)
throw gcnew Exception("Can't Pop from an empty Stack!");
else {
Object^ temp = first->Value;
first = first->Next;
return temp;
}
}
void Push(Object^ o) {
first = gcnew Node(o, first);
}
ref struct Node {
Node^ Next;
object^ Value;
Node(object^ value) : Node(value, nullptr) {}
Node(object^ value, Node^ next) {
Next = next;
Value = value;
}
};
private:
Node^ first;
};
int main()
{
Stack^ s = gcnew Stack();
for (int i = 0; i < 10; i++)
s->Push(i);
s = nullptr;
}
I get the following errors:
8_4.cpp
8_4.cpp(32) : error C2143: syntax error : missing ';' before '^'
8_4.cpp(32) : error C2501: 'Stack::Node:bject' : missing storage-class or
type specifiers
8_4.cpp(32) : error C2501: 'Stack::Node::Value' : missing storage-class or
type specifiers
8_4.cpp(33) : error C2143: syntax error : missing ')' before '^'
8_4.cpp(33) : error C2143: syntax error : missing ';' before '^'
8_4.cpp(33) : error C3149: 'Stack::Node' : cannot use this type here without
a top-level '^'
8_4.cpp(33) : error C2059: syntax error : ')'
8_4.cpp(33) : error C2065: 'value' : undeclared identifier
8_4.cpp(33) : fatal error C1903: unable to recover from previous error(s);
stopping compilation
I'm using .Net 2.0 Beta. Any clues?
-Don Kim