C++ 编译器在main中抛出错误,该错误以前未声明 #包括 #包括 使用名称空间std; 类customerNode{ 公众: 国际货币联盟; 整数; 字符串c_名称; 字符串类型; customerNode*下一个_节点; }; 类队列{ 公众: customerNode*front=NULL; customerNode*rear=NULL; int getc_id(); 字符串getc_name(); int getquantity(); int setc_id(int c_id); 字符串setc_名称(字符串c_名称); 整数设置数量(整数数量); void display(); 无效排队(整数c_id、整数数量、字符串c_名称); void dequeue(); int nor_队列、exp_队列; }; int队列::getc_id(){ 国际货币联盟; cout
具有类似错误的更简单示例是:C++ 编译器在main中抛出错误,该错误以前未声明 #包括 #包括 使用名称空间std; 类customerNode{ 公众: 国际货币联盟; 整数; 字符串c_名称; 字符串类型; customerNode*下一个_节点; }; 类队列{ 公众: customerNode*front=NULL; customerNode*rear=NULL; int getc_id(); 字符串getc_name(); int getquantity(); int setc_id(int c_id); 字符串setc_名称(字符串c_名称); 整数设置数量(整数数量); void display(); 无效排队(整数c_id、整数数量、字符串c_名称); void dequeue(); int nor_队列、exp_队列; }; int队列::getc_id(){ 国际货币联盟; cout,c++,declare,C++,Declare,具有类似错误的更简单示例是: #include<iostream> #include<string> using namespace std; class customerNode{ public: int c_id; int quantity; string c_name; string type; customerNode* next_node; }; class Queue{
#include<iostream>
#include<string>
using namespace std;
class customerNode{
public:
int c_id;
int quantity;
string c_name;
string type;
customerNode* next_node;
};
class Queue{
public:
customerNode* front=NULL;
customerNode* rear=NULL;
int getc_id();
string getc_name();
int getquantity();
int setc_id(int c_id);
string setc_name(string c_name);
int setquantity(int quantity);
void display();
void enqueue(int c_id,int quantity,string c_name);
void dequeue();
int nor_queue,exp_queue;
};
int Queue::getc_id(){
int c_id;
cout<<"enter customer id:"<<endl;
cin>>c_id;
return c_id;
}
int Queue::getquantity(){
int quantity;
cout<<"enter quantity customer purchased:"<<endl;
cin>>quantity;
return quantity;
}
string Queue::getc_name(){
string c_name;
cout<<"enter customer name:"<<endl;
cin>>c_name;
return c_name;
}
int Queue::setc_id(int c_id){
return c_id;
}
int Queue::setquantity(int quantity){
return quantity;
}
string Queue::setc_name(string c_name){
return c_name;
}
void Queue:: enqueue(int c_id,int quantity,string c_name){
int exp_queue,nor_queue;
cout<<"enter customer information"<<endl;
customerNode* new_node=new customerNode;
new_node->c_id=c_id;
new_node->c_name=c_name;
new_node->quantity=quantity;
new_node->next_node=NULL;
if(front==NULL){
rear=front;
rear=new_node;
rear->next_node=NULL;
}
else{
while(rear->next_node!=NULL)
rear=rear->next_node;}
rear->next_node=new_node;
rear=new_node;
if(new_node->quantity<=5)
{
new_node->type="express";
exp_queue++;
cout<<"customer entered in express queue"<<endl;
cout<<"total customer in express queue="<<exp_queue<<endl;
}
else{
new_node->type="normal";
nor_queue++;
cout<<"customer entered in normal queue"<<endl;
cout<<"total customer in normal queue="<<nor_queue<<endl;
}
}
void Queue::display(){
customerNode* ptr=front;
cout<<"normal queue customer information"<<endl;
while(ptr!=NULL)
{
if(ptr->type=="normal"){
cout<<"custumer name:"<<setc_name(ptr->c_name)<<endl;
cout<<"custumer id:"<<setc_id(ptr->c_id)<<endl;
cout<<"item puchased by custumer :"<<setquantity(ptr->quantity)<<endl;
nor_queue--;
cout<<"total customer in normal queue:"<<nor_queue<<endl;
}
ptr=ptr->next_node;
}
cout<<"express queue customer information"<<endl;
while(ptr!=NULL)
{
if(ptr->type=="normal"){
cout<<"custumer name:"<<setc_name(ptr->c_name)<<endl;
cout<<"custumer id:"<<setc_id(ptr->c_id)<<endl;
cout<<"item puchased by custumer :"<<setquantity(ptr->quantity)<<endl;
nor_queue--;
cout<<"total customer in normal queue:"<<exp_queue<<endl;
}
}
}
main(){
Queue q;
char i;
do{
q.enqueue(c_id,quantity,c_name );
cout<<"do you want to enter another customer?input y or Y for yes and n or N for no:";
cin>>i;
}
while(i=='y'||i=='Y');
q.display();
return(0);
};`
#include <iostream>
struct foo {
int x = 0;
int y = 0;
void assign(int a, int b){
x = a;
y = b;
}
};
int main()
{
foo f;
f.assign(x,y);
}
有一点让人惊讶的是,你用高级的东西编写代码,比如指针、类等等,但不知道范围。试着搜索“范围”并阅读它
代码中还有更多问题。例如
int Queue::setquantity(int quantity){return quantity;}
不设置任何内容。不过,正如我之前所写的,这太多的代码无法处理所有这些内容。我只能建议您从更少的代码开始,只有当您知道已经编译并通过测试的代码时,才能编写更多的代码。这不仅是对初学者的建议,而且任何人都会犯错误,您更希望这样做解决一个问题,然后同时解决多个问题。看来你已经跳过了入门书中的几个章节。如果你没有书要读,那么。请投资一些,从头开始阅读,不要跳过任何内容。完全同意@Someprogrammerdude。事实上,这种情况下的错误信息非常清楚:你是使用一些尚未定义的东西..变量定义和声明在任何程序员书籍的前10页都有解释,所以选择你最喜欢的一本,你会很容易找到解决方案
<source>: In function 'int main()':
<source>:14:14: error: 'x' was not declared in this scope
14 | f.assign(x,y);
| ^
<source>:14:16: error: 'y' was not declared in this scope
14 | f.assign(x,y);
| ^
int main(){ // main must return int
Queue q;
char i;
int c_id = 42;
int quantity = 0;
string c_name{"some fancy name"};
q.enqueue(c_id,quantity,c_name );
// ...
}