成员变量在一个成员函数的范围内而不是另一个成员函数

时间:2015-10-02 07:41:58

标签: c++

我很担心为什么会这样。我得到一个错误'enzyme_acronyms_未在此范围内声明'。它指向我的writeAcronym函数,但不是getAcronym,都使用了酶_acronyms_。什么可能导致这种情况?

SequenceMap.h

#include "SequenceMap.h"

string SequenceMap::getAcronym()
{
    return enzyme_acronyms_[0];        //works fine
}

void writeAcronym(string an_enz_acro)
{
    enzyme_acronyms_.push_back(an_enz_acro);     //enzyme_acronyms_ not declared in this scope
}

SequenceMap.cpp

 <html>
  <head>
  <title>order</title>
  </head>
  <body>
  <table>
  <form action="order2.php" method="post">
  <tr><td><input type="submit" name="submit" value="show"></td>
   <td><input type="submit" name="order" value="Order"></td>
   </tr>    
   </table>

    <!________________________________!>
    <?php
    $servername="localhost";
    $username="root";
    $password="";
    $database="mess_db";
    $con = mysql_connect($servername,$username,$password);
    if(!$con)
    {
        Die('Could not connect:'.mysql_error());
    }
    if($con)
    {
     echo "DB Connected<br>";
    }
    mysql_select_db($database,$con);
    if(isset($_POST["submit"]))
    {
        $sql="SELECT * FROM  menu";
        $result= mysql_query($sql,$con);
        echo '<select name="roti">';
            while($row = mysql_fetch_array($result))
        {

        echo '<option value="'. $row['roti'].'">' . $row['roti'].'';

        }
        echo '</select><br><br>';

    }
    if(isset($_POST["submit"]))
    {
        $sql="SELECT * FROM  menu";

        $result= mysql_query($sql,$con);

        echo '<select name="sabji">';


        while($row = mysql_fetch_array($result))
        {

        echo '<option value=" ' . $row['sabji'].'">' . $row['sabji'].'';

        }
        echo '</select><br><br>';

    }
    if(isset($_POST["submit"]))
    {
        $sql="SELECT * FROM  menu";

        $result= mysql_query($sql,$con);

        echo '<select name="daal">';


        while($row = mysql_fetch_array($result))
        {

        echo '<option value=" ' . $row['daal'].'">' . $row['daal'].'';

        }
        echo '</select><br><br>';

    }

    if(isset($_POST["submit"]))
    {
        $sql="SELECT * FROM  menu";

        $result= mysql_query($sql,$con);

        echo '<select name="sweet">';


        while($row = mysql_fetch_array($result))
        {

        echo '<option value=" ' . $row['sweet'].'">' . $row['sweet'].'';

        }
        echo '</select><br><br>';

    }

    if(isset($_POST["submit"]))
    {
        $sql="SELECT * FROM  menu";

        $result= mysql_query($sql,$con);

        echo '<select name="starter">';


        while($row = mysql_fetch_array($result))
        {

        echo '<option value=" ' . $row['starter'].'">' . $row['starter'].'';

        }
        echo '</select><br><br>';

    }
    if(isset($_POST["order"]))
    {
    echo "Hi...";
    $servername="localhost";
    $username="root";
    $password="";
    $database="mess_db";

    $con = mysql_connect($servername,$username,$password);

    if(!$con){
    Die('Could not connect:'.mysql_error());
             }

    if($con){
     echo "DB Connected<br>";
           }

    mysql_select_db($database,$con);
    if(!$_POST=="")
    {

    $sql="INSERT INTO order VALUES('$_POST[roti]')";
    $result=mysql_query($sql,$con);
    echo "Hello";
    }
    }
    mysql_close($con);
    ?>

2 个答案:

答案 0 :(得分:2)

您已经错过了第二个功能定义的SequenceMap::资格:

void SequenceMap::writeAcronym(string an_enz_acro)

答案 1 :(得分:1)

必须这样声明:

void SequenceMap::writeAcronym(string an_enz_acro)
{
    enzyme_acronyms_.push_back(an_enz_acro);
}

您忘记了课程范围SequenceMap::