Jump to content
  • Advertisement
Sign in to follow this  

free functions don't work in a class

This topic is 3157 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

How come this doesn't work?
#pragma once

#include "vec2d.h"

struct PortalTransform
    Vec2d origin_offset;
    Vec2d dest_offset;
    Vec2d origin_normal;
    Vec2d dest_normal;

    double Angle() const {return Angle(dest_normal) - Angle(origin_normal);}

#pragma once
#include <cmath>
//Other contents of header removed for brevity

inline double Angle(const Vec2d& arg)
    return atan2(arg.y, arg.x);

I assumed that PortalTransform::Angle() const would call the free function Angle(const Vec2d& arg), but apparently it throws a compiler error instead. Why?

Share this post

Link to post
Share on other sites
It's resolving the name "Angle" as "PortalTransform::Angle" and can't find an overload that takes one argument. It gives up before it goes out of the class scope. You have to tell it manually to look outside the class.

Put :: in front of the calls to the free-function.


double Angle() const {return ::Angle(dest_normal) - ::Angle(origin_normal);}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!