简体   繁体   中英

c++ compiler errors

I get the following error when trying to compile the following. (oops it didnt paste first try)

C:\\Users\\Owner\\Desktop\\Study\\C++\\Assignment 1\\Codeblocks\\Assignment2\\travelLength.h|24|error: multiple types in one declaration|

In the past I've always thought this to be a missing ";", however there is nothing missing this time (is there?). I have removed the #include "travelZone.h" from the example pasted below but i still get the error...ive had it with c++

yes im a student...frustrated...student

#ifndef TRAVELLENGTH_H
#define TRAVELLENGTH_H

#include<string>
#include<iostream>


class TravelLength
{
protected:
 int itsLengthMinutes;
 string itsName;

public:
 TravelLength();
 virtual ~TravelLength();

 virtual void print() = 0; //display output for a travelpass object
 virtual string getName() const = 0; //return string of its Name

 virtual float PriceAccept(TravelZone* theZone) =0;

    friend ostream& operator <<(std::ostream& outputStream, const TravelLength& thisTLength);
};

#endif

It looks like you are trying to use types that are part of the standard library (string, ostream) without referencing the standard name space. All of the types that are from the standard library should be prefaced with std::

Are you sure you corrected all the std:: problems?

This code compiles (as a single CPP file) without error, and looks OK to me:

#include<string>
#include<iostream>


class TravelZone;

class TravelLength
{
protected:
 int itsLengthMinutes;
 std::string itsName;

public:
 TravelLength();
 virtual ~TravelLength();

 virtual void print() = 0; //display output for a travelpass object
 virtual std::string getName() const = 0; //return string of its Name

 virtual float PriceAccept(TravelZone* theZone) =0;

    friend std::ostream& operator <<(std::ostream& outputStream, const TravelLength& thisTLength);
};

int main()
{
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM