c ++访问头文件信息

时间:2015-12-05 20:17:21

标签: c++ operator-overloading header-files

我正在尝试访问我在头文件中声明的变量。当我尝试将像女性这样的变量分配给0时,我收到一条错误,上面写着“'女性'未在此范围内声明。”我不确定这意味着什么。我是否必须再次在.cc文件中声明该变量,即使它包含school.h? 此外,我收到一个错误,我的重载赋值运算符读取“ISO C ++禁止声明'学校'没有类型,预期','或'...'在'&'标记之前,'bool运算符==( int)'必须有类或枚举类型的参数。“

school.cc

 #region Authentication
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(string username, string password)
        {
            // Lets first check if the Model is valid or not
            if (ModelState.IsValid)
            {
                

                    bool userValid = itreedb.Users.Any(user => user.UserName == username && user.Password == password && user.Approved == true);

                    // User found in the database
                    if (userValid)
                    {
                        //
                        // Save un and pw into cookies
                        HttpCookie auth = new HttpCookie("auth", Request.Form["username"] + "|" + Request.Form["password"]);
                        auth.Expires.AddDays(30);
                        Response.Cookies.Add(auth);

                        // Redirect the user to the index page
                        return Json(new { IsValidLogin = true });
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                
            }
            // If we got this far, something failed, redisplay form
            return View();
        }

school.h

#include "school.h"

void School ()
{
  women = 0;
  rateAI = 0;
  rateSys = 0;
  rateTheory = 0;
  effectiveness = 0;
  ratePubs = 0;
  overallRating = 0;
}

void School (string myName, string myState, int theWomen, int myRateAI, int myRateSys,int myRateTheory, int myEffectiveness, int myRatePubs)
{
  name = myName;
  state = myState;
  women = theWomen;
  rateAI = myRateAI;
  rateSys = myRateSys;
  rateTheory = myRateTheory;
  effectiveness = myEffectiveness;
  ratePubs = myRatePubs;
  overallRating = 0;


bool operator ==(const School &x, const School &y)
{
  return x.overallRating == y.overallRating;
}
bool operator >(const School &x, const School &y)
{
  return x.overallRating > y.overallRating;
}
bool operator <(const School &x, const School &y)
{
  x.overallRating < y.overallRating;
}
bool operator >=(const School &x, const School &y)
{
  x.overallRating >= y.overallRating;
}
bool operator <=(const School &x,const School &y)
{
  x.overallRating <= y.overallRating;
}
bool operator !=(const School &x, const School &y)
{
  x.overallRating != y.overallRating;
}

1 个答案:

答案 0 :(得分:1)

使用表单ClassName :: member name定义成员。

$(document).ready(function() {
  $('input:visible:enabled:first').focus();

  /*Change button text and show loading icon*/
  $('#loginbtn').click(function() {
    var img_route = "http://www.tutorialbunch.com/photoshop/animation/images/google-loading-icon11.gif";
    $('#loginbtn').attr("disabled", true).html('<img src="' + img_route + '" style="float:left;margin-right:0.5em;" height="21" width="21"> Logging in ...');
    $(this).parents('form').submit();
  });
});

这同样适用于您的其他成员。不是你的自由运营商。