错误:在'=='标记之前的预期primary-expression [英] Error: Expected primary-expression before '==' token

查看:96
本文介绍了错误:在'=='标记之前的预期primary-expression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做错了什么?

What Have I Done Wrong??

#include "placeName.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;

class RandonRegionName{
    public:

    int P_Name(){
    srand(static_cast<unsigned int>(time(0)));
    int placeName = rand();

    return (placeName % 3) + 1;
}

    void randomPlaceName(){
        string RegionName;
       if (placeName == 1){
        RegionName = "Pandonia";

       }else if (placeName == 2){
         RegionName = "Shires";
       }else if (placeName == 3){
          RegionName = "Epic";
       }

    }};

推荐答案

您正在尝试访问placeName,这是另一个叫做P_Name的函数里面的一个变量。



顺便说一下,如果你编写括号以便它们匹配,我认为你可以更好地理解它,如(并且我修改它以获得我认为你想要的东西)



You are trying to access "placeName" which is a variable inside another function called P_Name.

By the way, I think you may be able to understand it better if you wrote your brackets so they were matching, like (and I modified it to get what I think you want)

class RandonRegionName
{
    public:
 
    int P_Name()
    {
        srand(static_cast<unsigned int>(time(0)));
        int placeName = rand();
 
        return (placeName % 3) + 1;
    }
 
    void randomPlaceName()
    {
        string RegionName;
        int placeName = P_Name();

        if (placeName == 1)
        {
            RegionName = "Pandonia";
        }
        else if (placeName == 2)
        {
            RegionName = "Shires";
        }
        else if (placeName == 3)
        {
            RegionName = "Epic";
        }
 
    )
}





您还有额外的;在你的课程的底部,它不是一个错误,但你不需要它。



You also have an extra ; at the bottom of your class, its not an error, but you don't need it.


这篇关于错误:在'=='标记之前的预期primary-expression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆