Embarcadero C++ Builder - Public Function [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I got two forms (form_1 and form_2).
I made a function inside body of form_1.
void ExampleFunction() {
ShowMessage("I'm example function inside form_1");
}
and I want to call it from form_2.
I tryed to add this function to header file of form_1.
public: // User declarations
__fastcall Tform_2(TComponent* Owner);
void ExampleFunction();
};
but when I want to call it from form_2, like :
form_2->ExampleFunction();
Builder gives me a error : "[ilink32 Error] Error: Unresolved external"
So how can I do it properly to make it work ?

You are contradicting yourself. You said you want to implement the function in Form_1 and call it from Form_2, but you are trying to implement it in Form_2 and call it from outside of Form_2.
In any case, you declared the function as a member of the Tform_2 class, so you need to qualify the function's body as such:
void Tform_2::ExampleFunction() {
ShowMessage("I'm example function inside form_1");
}

Related

Undefined symbol error when use inline methods in C++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
When I make method as inline, compilation fails with this error:
Undefined symbol: 'int CPositionRequestor::State(void) const (?State#CPositionRequestor##QBEHXZ)'
Header file:
class CPositionRequestor : public CActive
{
// ...
private:
TInt iState;
public:
inline TInt State() const;
}
CPP file:
inline TInt CPositionRequestor::State() const
{
return iState;
}
An inline function needs it's definition to be available in the file that is calling that function.
So if You define it in one cpp file and try to call it in a second cpp file, then it will not be found.
What You need to do is move this definition into the h file. (just cut & paste it after the class definition).
Or as #einpoklum has noticed, if You don't need it, remove the inline from all the definitions.

Why can't static member methods access its non-static method in C++? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I had to make a callback interface for a new module while I work, so I made a static method in a class.
One thing I still don't understand is why I can't call a non-static member method in a static member like this :
class CAdapterUser
{
public:
CAdapterUser() {}
virtual ~CAdapterUser() {}
void Test();
void Test2();
protected:
CAdapter m_Adapter;
unsigned char buffer[16];
static void TestFunc(void* apContext);
};
void
CAdapterUser::TestFunc( void* apContext )
{
// CAdapterUser* pUser = (CAdapterUser*)apContext;
CAdapterUser* pUser = reinterpret_cast<CAdapterUser*>(apContext);
pUser->Test2(); // Compile error : LNK2019
pUser->buffer[0] = 1; // Even though I can access protected member variable?
}
Could someone answer my question?
LNK2019 is unresolved symbol, probably you simply forgot to implement Test2().

Calling scope resolution-ed CPP function from Objective C++ [duplicate]

This question already has answers here:
Inheritance - Symbol undefined Objective-C++
(1 answer)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I have a cpp function defined in a dynamic library like this
namespace A
{
namespace B
{
class C
{
public:
static funcA();
};
}
}
Now I am calling the above function from obcpp.mm file in the following manner:
void sample()
{
A::B::C::funcA();
}
This gives me error like Undefined Symbol A::B::C::funcA
Would highly appreciate any help regarding this.

using static member variable of a class inside a method of this same class [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
if I have a static member variable of a class A declared in the file Af.h
and I want to use this variable inside a method "met" of this same class inside the file Af.cpp, how do I proceed?
here is my files
Af.h
class A
{
public:
static std::vector <int> vec;
void met();
//....
};
Af.cpp
//...
void A::met()
{
// I will use here some int variable i
vec.push_back(i);
//...
}
Unfortunately,this code provides the following compiling error:
undefined reference to A::vec
You need to define it in Af.cpp:
std::vector<int> A::vec;

Undefined reference error to one class/file [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?
I have a game program and I am getting VERY frustrated. Everything was running fine, and I decided to clean up my program by making separate files for each set of functions. The code is very long with multiple files, but heres the basic idea:
Im on Windows XP using the Code::Blocks IDE
In my entity.h Ive declared all of my functions and variables for that class. In my entity.cpp Ive included it, as well as in all my other files. But Im still getting a huge list of errors that tell me I have an undefined reference to all of the methods in entity.h as well as all my other header files. For example, I have a function call print() to make it easier to print out things, and thats the first method I call from the entity.h file. I get this error:
Heres the code for print():
void print(string f) {
cout<<f<<endl;
}
How Im calling it:
void Player::win(){
entity e;
e.print("You have defeated the orc");
}
The error:
In function 'ZN6Player3winEv': undefined reference to 'entity::print(std::string)'
And yes, I do have an object of entity.
Its also happening for every single other function in the entity class and file.
void print(string f) {
cout<<f<<endl;
}
should be
void entity::print(string f) {
cout<<f<<endl;
}
void print(string f) {
cout<<f<<endl;
}
is a global function
if you want to call
e.print("You have defeated the orc");
then you need an implementation for
void entity::print(string f)