On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
Work* p = NULL;
if () {
p = new Work();
}
delete p;
std::unique_ptr<Work> p;
if () {
p = std::make_unique<Work>(); // простите, это Си++14, на 11 чуть не так.
}
for i:=length(s1)+1 to m do
s1:='0'+s1;
for i:=length(s)+1 to m do
s:='0'+s;
function add1(const large,small:string):string;
function add(const x, y : string) : string;
begin
if length(x) > length(y)
then add := add1(x, y)
else add := add1(y, x);
end;
TLongNum = record
length : integer;
data : array [1..1000] of byte;
end;
CONFIG -= qt
TEMPLATE = lib
CONFIG += staticlib
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS MUPARSER_STATIC
QMAKE_CXXFLAGS += -Wno-deprecated-copy -Wno-cast-function-type
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
src/muParser.cpp \
src/muParserBase.cpp \
src/muParserBytecode.cpp \
src/muParserCallback.cpp \
src/muParserError.cpp \
src/muParserInt.cpp \
src/muParserTest.cpp \
src/muParserTokenReader.cpp
HEADERS +=
INCLUDEPATH += include
DEFINES += MUPARSER_STATIC
INCLUDEPATH += ../MuParser/include
LIBS += -L$$PWD -lmuparser
pacboy sync muparser:i muparser:x
#include <iostream>
class Vocal { // интерфейс
public:
virtual void shout() = 0;
virtual ~Vocal() = default;
};
class Dog : public Vocal {
public:
virtual void shout() override { std::cout << "Woof!" << std::endl; }
};
class Unrelated {};
// ВАРИАНТ 1. Метод выкручивания рук.
void shoutAll_v1(Vocal** x, int n)
{
for (int i = 0; i < n; ++i)
x[i]->shout();
}
template <class T, int N>
inline void shoutAll_v1(T* (&x)[N]) {
// Тупая проверка концепции, ждём Си++20
static_assert (std::is_base_of<Vocal, T>(), "Need array of Vocal");
T** xx = x;
shoutAll_v1(reinterpret_cast<Vocal**>(xx), N);
}
// ВАРИАНТ 2. Виртуальный полиморфизм.
class Choir { // интерфейс
public:
virtual int size() const = 0;
virtual Vocal& at(size_t i) const = 0;
virtual ~Choir() = default;
};
void shoutAll_v2(const Choir& x)
{
int sz = x.size();
for (int i = 0; i <sz; ++i)
x.at(i).shout();
}
template <class T>
class VocalArray : public Choir {
public:
template <int N>
VocalArray(T* (&x)[N]) : fData(x), fSize(N) {}
int size() const override { return fSize; }
Vocal& at(size_t i) const override { return *fData[i]; }
private:
T** const fData;
int fSize;
};
int main()
{
Dog* sons[3];
for(auto& x : sons) {
x = new Dog;
}
//Unrelated* unrel[3];
std::cout << "V1" << std::endl;
shoutAll_v1(sons);
//shoutAll_v1(unrel); не компилируется
std::cout << "V2" << std::endl;
shoutAll_v2(VocalArray<Dog>(sons));
//shoutAll_v2(VocalArray<Unrelated>(unrel)); не компилируется
return 0;
}