Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:11:06+00:00 2026-06-01T12:11:06+00:00

okay, i’m a bit befuddled with this error. What i’m trying to do here

  • 0

okay, i’m a bit befuddled with this error. What i’m trying to do here is make a basic_string that will be either char or wchar_t when UNICODE and _UNICODE are defined (this is in WINAPI). This does work, but for some reason, i’m unable to define a function that receives a std::basic_string outside the class where it’s declared. Here’s an example:

test.h

#ifndef TEST_H
#define TEST_H

#include <Windows.h>
#include <string>

class Test
{
public:
    void func(std::basic_string<TCHAR> stringInput);
};

#endif

test.cpp

#include "test.h"

void Test::func(std::basic_string<TCHAR> stringInput)
{
    MessageBox(NULL, stringInput.c_str(), TEXT("It works!"), MB_OK);
}

This yields a link error, claiming the test::func was never defined. However, if i just define inside the class like this:

test.h

#ifndef TEST_H
#define TEST_H

#include <Windows.h>
#include <string>

class Test
{
public:
    void func(std::basic_string<TCHAR> stringInput)
    {
        MessageBox(NULL, stringInput.c_str(), TEXT("It works!"), MB_OK);
    }
}

#endif

it works fine. However, i really like to keep my declarations and definitions in separate files to avoid redefinition errors and for organization. Here’s the kicker though. when i have func defined in test.cpp like before and don’t define UNICODE and _UNICODE in my main.cpp, i don’t get the link errors. So really, the only time i get a link error is when TCHAR becomes a wchar_t. So here’s my main and the error real quick…

main.cpp

#define UNICODE       // this won't compile when these are defined
#define _UNICODE

#include <Windows.h>
#include <string>

#include "test.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
    Test test;
    test.func(TEXT("wakka wakka"));
    return 0;
}

error:

error LNK2019: unresolved external symbol "public: void __thiscall Test::func(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?func@Test@@QAEXV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function _WinMain@16

Anyone have a clue what’s going on and how i might go about fixing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:11:07+00:00Added an answer on June 1, 2026 at 12:11 pm

    I think because you are putting #define UNICODE in main.cpp, the other part doesn’t know about this. When test.cpp is compiled, UNICODE is not defined. You can try putting the UNICODE definition as project processor macro. Or in test.h, write #define UNICODE and #define _UNICODE before including Windows.h .

    On another note, because you’ve included Windows.h in Test.h, you should not include it again in main.cpp .

    Consider create a default project in visual studio, and use Precompiled Headers. This way, put such include in stdafx.h will address all your problems:

    #define UNICODE
    #include <windows.h>
    #include <string>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, I have done a bit of searching online and found this thread, but
Okay, none of the previous questions I have seen with this error seem to
Okay, so this is a long long shot but here it goes... When IE
Okay so the title may be a bit misleading. What I am trying to
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay i have this problem with every page i make. im not sure what
Okay, what have I done wrong here? I'm trying to .POST data from a
Okay, so I want to make a menu that expands down at the current
Okay, so this is complicated so try to bear with me, i will try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.