CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Apr 2008
    Posts
    725

    Re: how should I arrange classes in files?

    where is VideoEngine m_Video defined? where is it instantiated?

    Can you see that we are just going round a nd round in circles because you are not posting enough code?

    You should post a small and COMPLTE sample that reproduces your problem. Nobody can reproduce your problem because you keep leaving bits out!
    Last edited by Amleto; March 8th, 2011 at 07:23 AM.

  2. #17
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: how should I arrange classes in files?

    m_Video is instantiated in main.cpp but General.h declared it as extern (about this extern I have shown in the previous post)
    But that is meaningless, because if I write:
    Code:
    ID3D10Device* GetDevice() {return App::m_Video.m_pDevice; App::VideoEngine ve;}
    (the thing added is in blue) then it tells me "error C2079: 've' uses undefined class 'App::VideoEngine'". The problem is not with m_Video but with App::VideoEngine.

    I have attached a zip containing the files of the project.
    Attached Files Attached Files
    Last edited by Feoggou; March 8th, 2011 at 09:26 AM.

  3. #18
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: how should I arrange classes in files?

    a solution would be to define the GetDevice() function in a .cpp file (that would cause no error), but I don't understand the problem.

  4. #19
    Join Date
    Apr 2008
    Posts
    725

    Re: how should I arrange classes in files?

    below is what you have stated. It works fine. You aren't telling the whole story. post a small complete example that shows the problem. I looked your zip - it's not complete since it requires third party libs to build.

    gen
    Code:
    #pragma once
    
    namespace App
    {
    	class MainWnd;
    	class VideoEngine;
    
    	extern MainWnd			mainWnd;
    	extern VideoEngine	m_Video;
    }
    
    #include "Vid.h"
    vid
    Code:
    #pragma once
    
    #include "gen.h"
    
    namespace App
    {
      class VideoEngine
      {
      };
    }
    elem
    Code:
    #pragma once
    #include "gen.h"
    
    void func()
    {
      App::VideoEngine eng;
      App::m_Video = eng;
    }
    main
    Code:
    #include "elem.h"
    //#include "gen.h"
    int main()
    {
      func();
    }
    no errors.

  5. #20
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: how should I arrange classes in files?

    I've made a simple example.

    the compile error is in Exceptions.h, in the constructor, where it calls:
    Code:
    App::VideoEngine ve;
    the compile error is:
    Code:
    error C2079: 've' uses undefined class 'App::VideoEngine'
    The error seems to be caused by the inclusions of header files. For instance, if GameFont.h does not include any header file, the problem dissappears.

    I hope you can find the logic why it can't see the App::VideoEngine class, because I can't find it.
    Attached Files Attached Files
    Last edited by Feoggou; March 9th, 2011 at 07:22 AM. Reason: I have re-made the zip, because it contained no file.

  6. #21
    Join Date
    Apr 2008
    Posts
    725

    Re: how should I arrange classes in files?

    Quote Originally Posted by Feoggou View Post
    I've made a simple example.

    the compile error is in Exceptions.h, in the constructor, where it calls:
    Code:
    App::VideoEngine ve;
    Why are you writing implementation code in a header? Forward declaring lets you get away without #include-ing. BUT it means you cant use the type. You cant have your cake and eat it. Use of the type should be in a .cpp file where the type is 'fully' #include-ed

    The zip is empty.
    Last edited by Amleto; March 9th, 2011 at 07:04 AM.

  7. #22
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: how should I arrange classes in files?

    Quote Originally Posted by Amleto View Post
    Why are you writing implementation code in a header? Forward declaring lets you get away without #include-ing. BUT it means you cant use the type. You cant have your cake and eat it. Use of the type should be in a .cpp file where the type is 'fully' #include-ed
    Well, it was an easy thing to put the inline functions in the header and don't use another .cpp file for one or two short inline functions.

    Ok. thanks for helping me. The problem is solved. Perhaps I should care only not to use inline functions in headers if they require files included, rather than caring about why the headers get messed up.
    Last edited by Feoggou; March 9th, 2011 at 08:05 AM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured