Jump to content
  • Advertisement
Sign in to follow this  
FGFS

error: taking address of temporary [-fpermissive]

This topic is 2143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I get on the line: &Flughafen->toString()

the error: taking address of temporary [-fpermissive]

loopAirportpush returns passendeAirports:    std::vector<Airport*> passendeAirports;

Any ideas on how to avoid that error?

Many thanks

 

 

            stringstream bla;
            auto foundAirports = loopAirportpush("LSZH");

            cout << foundAirports.size() << " airports found: " << endl;

            for (auto it = foundAirports.begin(); it != foundAirports.end(); it++)
            {
                auto Flughafen = (*it);

            bla << " - " << &Flughafen->toString() << "\n";
            }
            return bla.str();

 

 

Share this post


Link to post
Share on other sites
Advertisement

What does the toString() function do and what does it return? Post for us both the definition and implementation of this function.

Share this post


Link to post
Share on other sites

class Airport : public Waypoint
{
public:

    Airport();

    Airport(const QString& id, const QString& name,
            const double& lat, const double& lon, int elevation_ft);

    virtual ~Airport() {};

...

    virtual QString toString() const;

 

...

 

 

-------

Thanks

Share this post


Link to post
Share on other sites

Do you know what the implemented (actually coded) contents of the toString() function are? Did you write this code?

Share this post


Link to post
Share on other sites

Couple of things:

 

1. If toString() is supposed to return a string object, then you probably shouldn't be taking the address of said object in order to print it out via an ostream.

2. You're taking the address of a temporary returned from a function. The warning is there because its attempting to tell you that the address is to a temporary object whose lifetime ends in the very near future.

3. I suspect your code is doing what you expect it to do.

Share this post


Link to post
Share on other sites

foundAirports is a std::vector<Airport*>

now how to get the name? The code is not mine (gpl) but I suppose that's what toString should be used for?

Thanks

Share this post


Link to post
Share on other sites


now how to get the name? 

Get the name of what exactly? You have a bunch of airports, are you trying to get the name of the first one? All of them?

 


The code is not mine (gpl) ...

Which code isn't yours? The Airport class, or perhaps QString?

 


... but I suppose that's what toString should be used for?

It depends on the codebase. Most I've come across treat toString() as a debugging tool, so the content is a convenient programmer's description of the object, but not necessarily suitable for an end user. But it really is down to the project conventions.

 

For example, an Aiport class might have a toString() that returns a compound string containing the human name and the airport code, e.g. "London Heathrow Airport [LHR]". In a database system, it might also include identifiers. Clients that wish to render a representation of the Airport would use member functions such as name() or getName(), code() or getCode() to build a U.I. suitable for end users. For instance, a HTML based U.I. might place tags around the name or code to emphasise or de-emphasise as necessary.

 

I think it is clearer to use explicit member functions to render objects, rather than rely on the programmers memory that Airport::toString() returns the name, for example.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!