return type ... differs from that in the declaration

I have two classes, Scene and ShaderInfo, and they need to know about each other. To avoid circular includes, I used a forward declaration of ShaderInfo in Scene, but now I'm getting this error:

return type of out-of-line definition of 'Scene::hitObjects' differs from that in the declaration


If I use normal include rather than forward declaration, I get an error saying

error: unknown type name 'ShaderInfo'
from the Scene class. What can I do to make this compile?
This happens when you have a member function declared as
1
2
3
class A{
    B foo();
};
and defined as
1
2
3
C A::foo(){
    //...
}
The return types have to match.
No, they are the same:

 
ShaderInfo hitObjects(Ray &ray, float &t);


and

1
2
ShaderInfo Scene::hitObjects(Ray &ray, float &t) {
...



EDIT: The full error msg is


error: return type of out-of-line definition of 'Scene::hitObjects' differs from that in the declaration
ShaderInfo Scene::hitObjects(Ray &ray, float &t) {
                  ^
../core/Scene.h:35:13: note: previous declaration is here
        ShaderInfo hitObjects(Ray &ray, float &t);
Last edited on
I feel like this is a long shot, but do you have ShaderInfo as a nested class inside Scene as well as outside, so that "ShaderInfo" refers to different classes in each position or something?
Maybe 'ShaderInfo' has a different meaning in the .cpp? If you tell your IDE to take you to the definition, does it take you to the same place from either location?
Thanks for your replies, I ended up doing things a little differently than I had planned. So, no solution to this one I'm afraid :P
Topic archived. No new replies allowed.