(Strange) C++ linker error in constructor

Posted by Microkernel on Stack Overflow See other posts from Stack Overflow or by Microkernel
Published on 2012-04-01T05:10:20Z Indexed on 2012/04/01 5:28 UTC
Read the original article Hit count: 129

Filed under:
|
|

I am trying to write a template class in C++ and getting this strange linker error and can't figureout the cause, please let me know whats wrong with this!

Here is the error message I am getting in Visula C++ 2010.

1>------ Rebuild All started: Project: FlashEmulatorTemplates, Configuration: Debug Win32 ------
1>  main.cpp
1>  emulator.cpp
1>  Generating Code...
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall flash_emulator<char>::flash_emulator<char>(char const *,struct FLASH_PROPERTIES *)" (??0?$flash_emulator@D@@QAE@PBDPAUFLASH_PROPERTIES@@@Z) referenced in function _main
1>C:\Projects\FlashEmulator_templates\VS\FlashEmulatorTemplates\Debug\FlashEmulatorTemplates.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Error message in g++

main.cpp: In function âint main()â:
main.cpp:8: warning: deprecated conversion from string constant to âchar*â
/tmp/ccOJ8koe.o: In function `main':
main.cpp:(.text+0x21): undefined reference to `flash_emulator<char>::flash_emulator(char*, FLASH_PROPERTIES*)'
collect2: ld returned 1 exit status

There are 2 .cpp files and 1 header file, and I have given them below.

emulator.h

#ifndef __EMULATOR_H__
#define __EMULATOR_H__

typedef struct {
    int property;
}FLASH_PROPERTIES ;

/* Flash emulation class */
template<class T>
class flash_emulator
{
private:
    /* Private data */
    int key;    

public:
    /* Constructor - Opens an existing flash by name flashName or creates one with 
       given FLASH_PROPERTIES if it doesn't exist */
    flash_emulator( const char *flashName, 
                       FLASH_PROPERTIES *properties );

    /* Constructor - Opens an existing flash by name flashName or creates one with 
       given properties given in configFIleName */
    flash_emulator<T>( char *flashName, 
                       char *configFileName );

    /* Destructor for the emulator */
    ~flash_emulator(){
    }
};

#endif  /* End of __EMULATOR_H__  */

emulator.cpp

#include <Windows.h>
#include "emulator.h"

using namespace std;


template<class T>flash_emulator<T>::flash_emulator( const char *flashName, 
                                                    FLASH_PROPERTIES *properties ) 
{
    return;
}

template<class T>flash_emulator<T>::flash_emulator(char *flashName,
                                char *configFileName)
{
    return;
}

main.cpp

#include <Windows.h>
#include "emulator.h"

int main()
{
    FLASH_PROPERTIES properties = {0};
    flash_emulator<char> myEmulator("C:\newEMu.flash", &properties);

    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++