2. extern "C"
extern "C" yazısına taşıdım.
3. extern "C++"
Bu kullanımı hiç görmedim ancak anladığım kadarıyla şöyle yapılabiliyor.
extern "C++" char* helloWorld() {
...
}
extern "C++" char* helloWorld() {
...
}
...taking the code in the function and injecting it into the place where it is called.1.1 Otomatik Inline
The C++ standard advises implementations to do this when they see an inline method or function, but does not require it. As such action has zero observable behavior changes in the abstract machine that the C++ standard describes, I consider it non-normative advice.
When a member function is defined inside a class definition, inline is implied.Açıklaması şöyle.
A member function may be defined in its class definition, in which case it is an inline member function, or it may be defined outside of its class definition if it has already been declared but not defined in its class definition.
#include <iostream>
class Greet
{
public:
void greet()
{
std::cout << "Hello World!" << std::endl;
}
};
A.cpp dosyasında şöyle yaparız.#include <iostream>
#include "Greet.h"
int main()
{
Greet G;
G.greet();
std::cin.get();
}
B.cpp dosyasında da şöyle yaparız.#include "Greet.h"
Normalde şöyle bir hata almamız gerekirdifatal error LNK1169: one or more multiply defined symbols found.
Ancak metod otomatik inline yapıldığı için sorun çıkmaz.An inline function (or in C++17 a variable) can exist in multiple translation units. Normally this causes an error at link-time; but when the variable or function is inline, instead all but one of the instances of the variable or function are silently discarded. If they differ in any important way, this makes your program ill-formed no diagnostic required.Örnek
This second meaning is why implicit ctors and dtors are implicitly inline; it means that no single translation unit has to be chosen for them to "live in". Instead, they are generated everywhere they are needed. They may be preferentially actually inlined into calling code, but most importantly if any vestigial copies of it still exist (because it was not inlined, say), no error occurs at link time, and instead all but one of them are discarded.
// file1.cpp
#include <iostream>
inline void foo()
{
std::cout << "f1\n";
}
void f1()
{
foo();
}
Diğer metod şöyle olsun// file2.cpp
#include <iostream>
inline void foo()
{
std::cout << "f2\n";
}
void f2()
{
foo();
}
Bu metodları çağıralım.void f1();
void f2();
int main()
{
f1();
f2();
}
Çıktı olarak şunu alırız.f1
f1
Açıklaması şöyle3. Inline Global DeğişkenAn inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case (3.2). [...]
#include <algorithm> // std::any_of
Birinci imza şöyle.template <class InputIterator, class Predicate>
bool any_of(InputIterator first, InputIterator last, Predicate pred);
İkinci imza şöyle.template <class ExecutionPolicy, class ForwardIterator, class Predicate>
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
Predicate pred);
Açıklaması şöyle. Muhtemelen short circuit yaparak ilk true veren elemanı görünce hemen döner.ÖrnekReturns: false if [first, last) is empty or if there is no iterator i in the range [first, last) such that pred(*i) is true, and true otherwise.Complexity: At most last - first applications of the predicate.
bool found = std::any_of(vector.begin(),
vector.begin(),
[](auto item) -> bool { return item == <xxx>; });
Örnek
#include <array> // std::array
#include <algorithm> // std::any_of
const std::array<char, 4> options{ '+', '-', '*', '/' };
const auto tester = [&temp](char c) { return temp->left->oper == c ||
temp->right->oper == c; };
const bool isValid = std::any_of(options.cbegin(), options.cend(), tester);
while(isValid) // now the while-loop is simplified to
{
// do something
}