error LNK2019: unresolved external symbol

hi everybody
i'm working under visualstudio2005

and i create a new namespase with some fonction ;
after i have another class in a different file and when i call myfonction og my namespace i have this erreurs

error LNK2019: unresolved external symbol "void __cdecl mynamespace::myfonction() referenced in function

Linker errors can be quite hard to track down so without any code to examine the job is made ever so slightly more difficult ;)
Post up some of the code that you think could be associated to or causing your problems.

Side note: Your punctuation and grammar is quite poor so I would appreciate if you could take your time writing your posts so that they are easier to read :)

Linker errors can be quite hard to track down so without any code to examine the job is made ever so slightly more difficult ;)
Post up some of the code that you think could be associated to or causing your problems.

Side note: Your punctuation and grammar is quite poor so I would appreciate if you could take your time writing your posts so that they are easier to read :)

The OP is from France, I think their post is a direct translation from French, which (as a Romance language) has a grammar structure that is somewhat different from English (a Germanic language).

@OP:

  1. Check that you have resolved your namespace(s) correctly.
  2. Check that you have included all the correct files in your compilation. If you missed the function's implementation file, you will get a link error.
  1. Est-ce que vous avez resolu vos "namespace" correctement?
  2. Est-ce que vous avez inclus tous des documents dans votre programme? Si vous oubliez le document d'implementation, vous obtiendrez une error de lien.

what do you mean by resolve my namespace correctly ...


caged_fire : i swear i will buy a book of grammare language and french ....
fbody : sorry but german not yet :)

>>fbody : sorry but german not yet :)
I'm afraid I don't understand, but if I've offended you, I apologize.

A Linker error usually occurs when you attempt to call a function that is known to exist, but the implementation for it can't be found. If you define a function within a namespace, you have to resolve, or "bring into view", the namespace when you attempt to use/call the function. I suspect that you have already done this properly for your call since you are getting a Linker error, not a Compiler error. If you had this part incorrect, you would generally get a Compiler error concerning undeclared identifiers.

Would you please post the implementation file for your function? I suspect the definition of the function is not properly resolved into the namespace. As a result, the function exists, but not where/how you think it does.

For example:

#include "myOtherClass.h"
using namespace exampleNamespace;

int main(void)
{
    exampleNamespaceFunc();   

   return 0;
}
#include "myOtherClass.h"

int main(void)
{
    exampleNamespace::exampleNamespaceFunc();   

   return 0;
}

Notice that when 'using namespace' isn't used, the scope resolution operator is required ( :: )

and can i have u r declaration of u r namespace ?


and what i'm doing to work it's to declare a class IN my namspace , and in this class i create a virtual function , and he work .

so i ha ve another question , can i declare a virtual function in my namespace ?

This was just an example, I don't have an actual declaration for this namespace. It could look like this however:

namespace exampleNamespace
{
    /* functions etc. go here */
}

can i declare a virtual function in my namespace ?

Yes

You can perform any legal C++ action inside a namespace. You can even declare "sub-"namespaces. The thing you need to remember is that if you don't resolve the namespace(s) properly, nothing will work.

header file (Sample.h):

namespace Sample {
  void someFunc();
} //end Sample namespace

iplementation file (version 1, sample1.cpp):

#include "Sample.h"
namespace Sample {
  void someFunc() {
    /* ... do something ... */
  } //end someFunc()
} //end Sample namespace

iplementation file (version 2, sample2.cpp):

#include "Sample.h"
void Sample::someFunc() {
  /* ... do something ... */
} //end someFunc()

Main file v1 (main1.cpp)

#include "Sample.h"
int main() {
  Sample::someFunc();
  return 0;
}

Main file v2 (main2.cpp)

#include "Sample.h"
using namespace Sample;
int main() {
  someFunc();
  return 0;
}

Main file v3 (main3.cpp)

#include "Sample.h"
using Sample::someFunc();
int main() {
  someFunc();
  return 0;
}

i see it first but in my place i can do anything , i don't have a choice , i expose my solution in my last post , but i don't think that's the solution for this error , so don't affect this thread as resolved !!!!

and thank you fbody for u r help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.