我哪里犯了错误
Where am I making a mistake?
本文关键字:错误 更新时间:2023-10-16
这是一个学校的工作,用于制作一个计算面积和周长的程序编译器/语法错误"预期;在 void 之前"和"在 void 之前预期的主要表达式"。我不知道问题是否在头文件中。
#include"shape.h"
#include<iostream>
using namespace std;
Shapes::Shapes()//base class
{status=true;}
void Shapes::launch()
{cout<<"Which figure are we working on ?"<<endl;
cout<<"Square(1),Triangle(2),Rectangle(3);"<<endl;
cout<<"Circle(4) or regular polygons(5)"<<endl;
cin>>a;}
void Shapes::aime()//mistake here.
{ //switch to decide shape
if (status) switch(a){
case'1':{Square::Square()
void Square::readSide()//mistake too.
{cout<<"The length of one side in metres : t";
cin>>side;}
void Square::getsPerimeter()//another mistake.
{cout<<"The perimeter is "<<(side*4)<<" metres."<<endl;}
void Square::getsArea(){cout<<"The Area is "<<(side*side)<<" squared
metres."<<endl;}//again.
}
case'2':{Triangle::Triangle()
void Triangle::readData()//mistake
{cout<<"The length of the base in metres : t";
cin>>base;
cout<<"The length of the height in metres : t";
cin>>height;}
void Triangle::gettArea()//error
{cout<<"The Area is "<<(height*base/2)<<endl;}
}
case'3':{Rectangle::Rectangle()
void Rectangle::readDatar()//error
{cout<<"The length in metres : t";
cin>>length;
cout<<"The width in metres : t";
cin>>width;}
void Rectangle::getrArea()//error
{cout<<"Area is "<<(length*width)<<" squared metres."<<endl;}
void Rectangle::getrPerimeter()
{cout<<"Perimeter is "<<(2*(length+width))<<" metres."<<endl;}
}
case'4':{Circle::Circle()
void Circle::readRadius(){cout<<"The length of the radius in metres : t";
cin>>radius;}
void Circle::getCirc()//error
{cout<<"Circumference is "<<(2*3.14159*radius)<<" metres."<<endl;}
Circle::getcArea()//error
{cout<<"Area is "<<(radius*radius*3.14159)<<" squared metres."<<endl;}
}
case'5':{Polygon::Polygon()
void Polygon::readDatap(){cout<<"The number of sides : t";//error
cin>>num;
cout<<"The length of one side in metres : t";
cin>>pside;
cout<<"The length of the apothem in metres : t";
cin>>apothem;}
void Polygon::getpPerimeter()//error
{cout<<"The perimeter is "<<(num*pside)<<" metres."<<endl;}
void Polygon::getpArea()//another error
{cout<<"The area is "<<(num*pside*apothem/2)<<" squared metres."<<endl;}
}
} //switch() terminated
} //aime() terminated
bool Shapes::run(){return status;}
//to keep the app open
//the classes are derived classes of the base class:Shapes
你在switch语句中定义了一个函数,这在C++中是不允许的(lambdas/函子除外,但它们是另一个时间的主题(。
您需要在 switch 语句之外定义函数,并从那里调用它们。下面是您正在做的事情的示例(这是错误的(:
#include <iostream>
int main(int argc, char** argv) {
switch(argc) {
case 1:
void example(){ std::cout<< "The number of sides : t"; }
break;
}
}
这是您需要做的:
#include <iostream>
void example() { std::cout<< "The number of sides : t"; }
int main(int argc, char** argv) {
switch(argc) {
case 1:
example();
break;
}
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'