1

WTL is template library, so i have to implement it in template library header file.

I want to implement my logic in .cpp file otherwise, i will have to code a huge header file.

for example, in MainFrm.h

// ...
// MainFrm.h
class CMainFrame : 
    public CFrameWindowImpl<CMainFrame>, 
    public CUpdateUI<CMainFrame>,
    public CMessageFilter, public CIdleHandler
{
  //...
  void function1()
  {
    //...
  }

  void function2()
  {
    //...
  }
}

I want to have function1() and function2() in myfunction.cpp, how to do it?

Please guide.

EDIT:

Solved! thanks to Jan S. i had include myfunction.cpp into WTL project and add some lines:

MainFrm.h:

// ...
// MainFrm.h
#if 1
#include <atlframe.h>
#include <atlsplit.h>
#include <atlctrls.h>
#include <atlctrlw.h>
#include <atlctrlx.h>
#include "sampleView.h"
#include "resource.h"
#endif

// MainFrm.h
class CMainFrame : 
    public CFrameWindowImpl<CMainFrame>, 
    public CUpdateUI<CMainFrame>,
    public CMessageFilter, public CIdleHandler
{
  //...
  void functionx();
  //...
};

myfunction.cpp:

// myfunction.cpp
#include "stdafx.h" 
#include "MainFrm.h"
void CMainFrame::functionx()
{
  //...
}
sailfish009
  • 2,561
  • 1
  • 24
  • 31
  • 1
    Difference between a c++ definition and declaration http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration – Jan S Jan 25 '17 at 14:38
  • 1
    You may be thinking of a template before it is explicitly instantiated http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – Jan S Jan 25 '17 at 16:49

1 Answers1

1

In your header put the declaration

// MainFrm.h
class CMainFrame : 
    public CFrameWindowImpl<CMainFrame>, 
    public CUpdateUI<CMainFrame>,
    public CMessageFilter, public CIdleHandler
{
  //...
  void functionx();
  //...
};

In your .cpp file put the definition

#include MainFrm.h

void CMainFrame::functionx()  
{  
    // more code  
} 

The compiler errors

You seem to be missing WTL header includes

#include <atlframe.h>
#include <atlsplit.h>

Off topic but, in your header make sure you have

#pragma once

or

#ifndef UNIQUE_HEADER_NAME
#define UNIQUE_HEADER_NAME
//header code
#endif

This will stop duplicate declarations.

Jan S
  • 408
  • 6
  • 15