LNK2020 sÝmbolo(令牌)sin 解析器 (06000006) AStack::.ctor [C++/CLI]
LNK2020 sÝmbolo (token) sin resolver (06000006) AStack::.ctor [C++/CLI]
我在尝试编译时遇到此错误,知道发生了什么吗?我认为这与整数 maxSize 和 top 有关。当我尝试将它们更改为 "int^ maxSize" 之类的内容时,我无法使用这些整数来管理数组位置。非常感谢!
AStack.h
#pragma once
#include "Carta.h"
#define defaultSize 2048
ref class AStack
{
private:
int maxSize;
int top;
array< Carta^ >^ ListArray; //puntero a arreglo
public:
AStack();
AStack(int size) {
maxSize = size;
top = 0;
ListArray = gcnew array< Carta^ >(size);
}
~AStack() { delete[] ListArray; }
void clear() { top = 0; }
void push(Carta^ pElement) {
if (top == maxSize) {
Console::WriteLine("Stack is full");
}
ListArray[top++] = pElement;
}
Carta^ pop() {
if (top == 0) {
Console::WriteLine("Stack empty");
}
return ListArray[--top]; //retorna top y despues lo decrementa
}
Carta^ topValue() {
if (top == 0) {
Console::WriteLine("Stack empty");
}
return ListArray[top - 1];
}
int length() {
return top; //largo de pila
}
};
Carta.h
#pragma once
using namespace System;
ref class Carta
{
private:
String^ cara;
String^ palo;
String^ direccion;
public:
Carta();
Carta(String^ pCara, String^ pPalo) {
cara = pCara;
palo = pPalo;
direccion = pCara + pPalo;
}
String^ print() {
return (cara + " de " + palo);
}
String^ getDireccion() {
return direccion;
}
};
Deck.h
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include "Carta.h"
#include "AStack.h"
#define ARRAY_SIZE 54
using namespace System;
ref class Deck
{
private:
array< Carta^ >^ deck = gcnew array< Carta^ >(ARRAY_SIZE);
int posicion;
bool ya;
public:
Deck() {
ya = false;
array<String^>^ caras = { "As","Dos","Tres","Cuatro","Cinco","Seis","Siete","Ocho","Nueve","Diez",
"Jack","Dama","Rey" };
array<String^>^ palos = { "Corazon","Diamante","Espada","Trebol" };
for (int i = 0; i < ARRAY_SIZE - 2; i++) {
deck[i] = gcnew Carta(caras[i % 13], palos[i / 13]);
}
deck[52] = gcnew Carta("Joker", "Negro");
deck[53] = gcnew Carta("Joker", "Rojo");
}
~Deck() {
delete[]deck;
}
void mostrar() {
for (int i = 0; i<54; i++) {
Console::WriteLine(deck[i]->print());
}
}
void mezclar() {
for (int primero = 0; primero < 54; primero++) {
int segundo = (rand() + time(0)) % 54;
Carta^ temp = deck[primero];
deck[primero] = deck[segundo];
deck[segundo] = temp;
}
}
Carta^ topCarta() {
return deck[0];
}
void cortar(int pos) {
if (pos != 0 && pos != 53) {
AStack^ pila;
for (int i = pos; i < 54; i++) {
pila->push(deck[i]);
}
for (int j = 0; j < pos; j++) {
pila->push(deck[j]);
}
for (int k = 0; k < 54; k++) {
deck[k] = pila->pop();
}
}
}
};
简单的答案
不要重新发明轮子。使用 .Net 库 class System::Collections::Generic::Stack.
更复杂的答案
AStack();
这几乎可以肯定是导致错误的原因:您已经声明了一个无参数构造函数,但从未实现它。
Carta();
这里也是一样。
~AStack() { delete[] ListArray; }
这是错误的:delete[]
是分配给 new
的东西。用 gcnew
分配的东西不需要 delete[]
。 (你确实使用 delete
,没有 []
,到 Dispose objects, but array isn't an IDisposable。)
我在尝试编译时遇到此错误,知道发生了什么吗?我认为这与整数 maxSize 和 top 有关。当我尝试将它们更改为 "int^ maxSize" 之类的内容时,我无法使用这些整数来管理数组位置。非常感谢!
AStack.h
#pragma once
#include "Carta.h"
#define defaultSize 2048
ref class AStack
{
private:
int maxSize;
int top;
array< Carta^ >^ ListArray; //puntero a arreglo
public:
AStack();
AStack(int size) {
maxSize = size;
top = 0;
ListArray = gcnew array< Carta^ >(size);
}
~AStack() { delete[] ListArray; }
void clear() { top = 0; }
void push(Carta^ pElement) {
if (top == maxSize) {
Console::WriteLine("Stack is full");
}
ListArray[top++] = pElement;
}
Carta^ pop() {
if (top == 0) {
Console::WriteLine("Stack empty");
}
return ListArray[--top]; //retorna top y despues lo decrementa
}
Carta^ topValue() {
if (top == 0) {
Console::WriteLine("Stack empty");
}
return ListArray[top - 1];
}
int length() {
return top; //largo de pila
}
};
Carta.h
#pragma once
using namespace System;
ref class Carta
{
private:
String^ cara;
String^ palo;
String^ direccion;
public:
Carta();
Carta(String^ pCara, String^ pPalo) {
cara = pCara;
palo = pPalo;
direccion = pCara + pPalo;
}
String^ print() {
return (cara + " de " + palo);
}
String^ getDireccion() {
return direccion;
}
};
Deck.h
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include "Carta.h"
#include "AStack.h"
#define ARRAY_SIZE 54
using namespace System;
ref class Deck
{
private:
array< Carta^ >^ deck = gcnew array< Carta^ >(ARRAY_SIZE);
int posicion;
bool ya;
public:
Deck() {
ya = false;
array<String^>^ caras = { "As","Dos","Tres","Cuatro","Cinco","Seis","Siete","Ocho","Nueve","Diez",
"Jack","Dama","Rey" };
array<String^>^ palos = { "Corazon","Diamante","Espada","Trebol" };
for (int i = 0; i < ARRAY_SIZE - 2; i++) {
deck[i] = gcnew Carta(caras[i % 13], palos[i / 13]);
}
deck[52] = gcnew Carta("Joker", "Negro");
deck[53] = gcnew Carta("Joker", "Rojo");
}
~Deck() {
delete[]deck;
}
void mostrar() {
for (int i = 0; i<54; i++) {
Console::WriteLine(deck[i]->print());
}
}
void mezclar() {
for (int primero = 0; primero < 54; primero++) {
int segundo = (rand() + time(0)) % 54;
Carta^ temp = deck[primero];
deck[primero] = deck[segundo];
deck[segundo] = temp;
}
}
Carta^ topCarta() {
return deck[0];
}
void cortar(int pos) {
if (pos != 0 && pos != 53) {
AStack^ pila;
for (int i = pos; i < 54; i++) {
pila->push(deck[i]);
}
for (int j = 0; j < pos; j++) {
pila->push(deck[j]);
}
for (int k = 0; k < 54; k++) {
deck[k] = pila->pop();
}
}
}
};
简单的答案
不要重新发明轮子。使用 .Net 库 class System::Collections::Generic::Stack.
更复杂的答案
AStack();
这几乎可以肯定是导致错误的原因:您已经声明了一个无参数构造函数,但从未实现它。
Carta();
这里也是一样。
~AStack() { delete[] ListArray; }
这是错误的:delete[]
是分配给 new
的东西。用 gcnew
分配的东西不需要 delete[]
。 (你确实使用 delete
,没有 []
,到 Dispose objects, but array isn't an IDisposable。)