c++

c++一本通1000

萝らか妹 提交于 2021-02-19 03:47:36
http://ybt.ssoier.cn:8088/problem_show.php?pid=1000 #include<iostream> #include <cstdio> using namespace std; int main() { int a,b; scanf( " %d%d " ,&a,& b); printf( " %d " ,a+ b); return 0 ; } 入门是一个艰辛的过程O(∩_∩)O~ 来源: oschina 链接: https://my.oschina.net/u/4399096/blog/3931192

function returning std::string crashes without return statement, unlike a function returning int without return statement

[亡魂溺海] 提交于 2021-02-19 03:47:09
问题 #include <iostream> #include <string> using namespace std; string crash() { } int noCrash() { } int main() { crash(); // crashes // noCrash(); // doesn't crash return 0; } The function crash(), crashes with Mingw g++ 4.6.2 and the function noCrash() executes with no issues. Why does the function returning string crash without a return statement? 回答1: Both are undefined behaviors, even noCrash can crash. 回答2: From standard 6.6.3/2 A return statement without an expression can be used only in

No linker error when global variable declared static in the header file [duplicate]

六眼飞鱼酱① 提交于 2021-02-19 03:46:48
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Static variables in C++ // x.h int i = 3; // x1.cpp #include"x.h" //... // x2.cpp #include"x.h" //... Above code will give linker error. However If I declare, //x.h static int i = 3; It doesn't give linker error in gcc, even we have the same #include ! Are we creating different static int i; for every .cpp file ? Will it cause any silent linking bug (due to same name)? 回答1: Are we creating different static int i

LNK2019 - why unresolved external with template friend function

£可爱£侵袭症+ 提交于 2021-02-19 03:37:08
问题 I don't get this error: #include <iostream> using namespace std; // LNK2019f.cpp // LNK2019 expected template<class T> void f(T) {} template<class T> struct S { friend void f(T); // try the folowing line instead // friend void f<T>(T); }; int main() { S<int> s; int a = 2; f(a); // unresolved external } Taken from http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx Why does the error not show up if I comment out S< int > s ? I got that I need to declare the template argument list as

Numerically calculate combinations of factorials and polynomials

一个人想着一个人 提交于 2021-02-19 03:36:29
问题 I am trying to write a short C++ routine to calculate the following function F(i,j,z) for given integers j > i (typically they lie between 0 and 100) and complex number z (bounded by |z| < 100), where L are the associated Laguerre Polynomials: The issue is that I want this function to be callable from within a CUDA kernel (i.e. with a __device__ attribute). Standard library/Boost/etc functions are therefore out of the questions, unless they are simple enough to re-implement on my own - this

C4297 warning in Visual Studio while using function-try-block (function assumed not to throw an exception but does)

我的梦境 提交于 2021-02-19 03:28:52
问题 #include <exception> struct FOO { ~FOO() try { throw std::exception(); } catch (...) { return; // Shall prevent the exception from being rethrown? } }; Building this code in Visual Studio triggers C4297 warning (function assumed not to throw an exception but does). Reaching the end of a catch clause for a function-try-block on a destructor also automatically rethrows the current exception as if by throw;, but a return statement is allowed . quoted from cppreference.com; Do I interpret this

Alternatives to writing an ODBC driver

自闭症网瘾萝莉.ら 提交于 2021-02-19 03:23:32
问题 We are storing allot of time series data into our own proprietary "database". In the next version of our system we want to give our users a simple query mechanism to extract the raw data from the database (as a complement to the reports our system can create) by using standard tools. I have looked at the possibility to write an ODBC driver, but it looks like quite a daunting task, especially when the use will be very simple select statements. I would be grateful for any tips, ideas and/or

convert eclipse formating to .clang-format or use eclipse formatter in vscode

风流意气都作罢 提交于 2021-02-19 03:19:58
问题 In my project (C/C++) I use slightly modified formatting from eclipse default formatter (bsd/allman + spaces over tabs). I would like to switch the editor, and to do so, I have to have correct formatter. Is there a way to convert .xml file with formatting exported from eclipse, to .clang-format file ? I aim to have exactly the same formatting, and I do not want to reformat the project, just because I switched the editor Optionally, is there a way to use eclipse formatter in vscode for C/C++

Where is the performance gain of the erase-remove idiom coming from

南笙酒味 提交于 2021-02-19 03:15:40
问题 I need to erase all elements from a vector which fulfill a certain criteria. My first approach would be to loop through the vector and call vector::erase on all elements which fulfill the criteria. As far as I understand, vector::erase has a bad performance for this use case, because it removes the item from the underlying array, and moves the rest of the vector forward by one element (or more if you erase a range of elements). When you remove multiple elements, the rear elements will be

Passing an integer or a type as a template parameter?

邮差的信 提交于 2021-02-19 03:12:58
问题 Here is an example case of what I'm trying to do (it is a "test" case just to illustrate the problem) : #include <iostream> #include <type_traits> #include <ratio> template<int Int, typename Type> constexpr Type f(const Type x) { return Int*x; } template<class Ratio, typename Type, class = typename std::enable_if<Ratio::den != 0>::type> constexpr Type f(const Type x) { return (x*Ratio::num)/Ratio::den; } template</*An int OR a type*/ Something, typename Type> constexpr Type g(const Type x) {