[英]'std::list<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::list<_Ty>' to 'std::list<_Ty> &'
[英]Cannot convert 'this' pointer from 'std::stack<_Ty>' to 'std::stack<_Ty> &'
我正在實現一個Visual C ++項目,它使用Windows窗體。 我需要使用C ++堆棧,而我使用stack<>
。 但是它給出了這個錯誤。 我包括#include <stack>
並using namespace std;
在using namespace std;
添加之前using namespace std;
它說未聲明的標識符。 但是添加后,它會給出此錯誤。 我是C ++的新手。 誰能解釋我為什么會這樣。 謝謝...!
我的代碼的一部分:
stack<int> TA;
stack<int> TB;
stack<int> TC;
void move_a_to_b(){
if(TB.top() < TA.top()){
B[index_of_b + 1]->Image = A[index_of_a]->Image;
B[index_of_b + 1]->Visible = true;
A[index_of_a]->Visible = false;
index_of_a--;
index_of_b++;
TB.push(TA.top());
TA.pop();
}
else
MessageBox::Show("Invalid Move","Error",MessageBoxButtons::OK,MessageBoxIcon::Exclamation);
}
我找到了解決方案。 發生這種情況是因為我將非托管版本的stack
與托管版本一起使用。 不得使用new
關鍵字初始化堆棧。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.