1

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 
5
  • I think you need to tell us the error you're getting. BTW, because you removed "travelZone.h", TravelZone is now an unknown type, at least forward declare it. Commented Nov 9, 2010 at 21:23
  • In which line is the error reported? Commented Nov 9, 2010 at 21:59
  • @Oli: apologies to all: error pasted in above: I removed that include and commented out that line to see if that header was causing the pblm...the pasted code...was somewhere inbetween: Ditto the missing std:: this is a 2 part assignment and somewhere along the line i learnt the "error" of "using namespace" evilness Commented Nov 9, 2010 at 21:59
  • @Vlad It was reporting it for the final line }; ?? Commented Nov 9, 2010 at 21:59
  • 1
    Hmm... Actually this is strange, as the compilation should have stopped before. Wait, where do you include this file from? You must see this in the error message. Please paste that file, too (at least the part before the #include). Commented Nov 9, 2010 at 22:03

2 Answers 2

3

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::

Sign up to request clarification or add additional context in comments.

3 Comments

the pblm wasnt the missing std... could it be that in an unrelated class (user) I was missing a semi-colon??
From your edit you only added std:: to one instance of ostream. You will also need it on the return of that function and on the return type of the getName function.
@user349456: If you still get the error after changing string to std::string and ostream to std::ostream, you need to do something about TravelZone. Also, exactly which line gives you the error?
0

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; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.