![](/img/trans.png)
[英]C++: “Expected '(' for function-style cast or type construction” Error
[英]c++ Xcode expected '(' for function-style cast or type construction
我正在嘗試編譯此cpp和h文件,但它一直給我這個錯誤“預期'('用於函數式類型轉換或類型構造”,它指向構造函數
GasTank::GasTank(double a){
capacity=a;
}
有什么想法嗎? 我不知道為什么會給我這個錯誤。 這是其余的代碼:
//
// Header.h
// labs
//
// Created by Pxndroid on 10/17/14.
// Copyright (c) 2014 Pxndroid. All rights reserved.
//
#include<string>
using namespace std;
class GasTank
{
private:
double amount;
double capacity;
public:
GasTank(double a);
void addGas(double b);
void useGas(double c);
bool isEmpty();
bool isFull();
double getGasLevel();
double fillUp();
};
和:
//
// main.cpp
// labs
//
// Created by Pxndroid on 10/17/14.
// Copyright (c) 2014 Pxndroid. All rights reserved.
//
#include <iostream>
#include "Header.h"
using namespace std;
int main()
{
GasTank::GasTank(double a){
capacity=a;
}
void GasTank::addGas(double b){
if((amount+b)>capacity){
amount=capacity;
}
else{
amount+=b;
}
}
void GasTank::useGas(double c){
if((amount-c)<0){
amount=0;
}
else{
amount-=c;
}
}
bool GasTank::isEmpty(){
if(amount<0.1){
return true;
}
else{
return false;
}
}
bool GasTank::isFull(){
if(amount>capacity-0.1){
return true;
}
else{
return false;
}
}
double GasTank::getGasLevel(){
return amount;
}
double GasTank::fillUp(){
capacity-=amount;
amount+=capacity;
return capacity;
}
}
將GasTank
成員的定義GasTank
int main()
。 它們不屬於它們,並且編譯器不期望它們。 它們不是main()
函數的一部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.