2018-10-22         Nora

Troubles getting boost::logger to compile

I'm struggling with getting some boost::logging demo application running. I've got the following:logger.cpp:#include <iostream>#include <boost/fusion/iterator/equal_to.hpp>#include <boost/log/core.hpp>#include <boost/log/trivial.hpp>#include <boost/log/expressions.hpp>#include <boost/log/utility/setup/file.hpp>namespace logging = boost::log;namespace src = boost::log::sources;namespace sinks = boost::log::sinks;namespace keywords = boost::log::keywords;namespace expr = boost::log::expressions;void init(){ logging::add_file_log("sample....

 c++                     1 answers                     96 view
 2018-10-22         Alston

Difference between const auto & and auto & if object of reference is const

// case 1const int i = 42;const auto &k = i;// case 2const int i = 42;auto &k = i;Do we need the const keyword before auto in this scenario? After all, a reference (k) to an auto-deduced type will include the top level const of the object (const int i). So I believe k will be a reference to an integer that is constant (const int &k) in both cases.If that is true, does that mean that const auto &k = i; in case 1 is replaced by the compiler as just const int &k = i; (auto being replaced with int)? Whereas in case 2, auto is replaced with const int? auto...

 c++                     5 answers                     97 view
 2018-10-22         Dean

Assimp library error: taking address of packed member

I wanna implement assimp library in my NDK project with android studio, everything works fine but once i tried to use materials I got the following error:assimp/types.h:208:19: error: taking address of packed member 'r' of class or structure 'aiColor3D' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] return *(&r + i);this is CMakeLists flagsset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -Werror") This issue should be fixed on the latest version. You can get the current master from github [XXX]

 c++                     1 answers                     98 view
 2018-10-22         Dorothy

I don't understand the definition of DoNotOptimizeAway

I am checking on Celero git repository the meaning of DoNotOptimizeAway. But I still don't get it. Could you please help me understand it in layman's terms please. As much as you can. The celero::DoNotOptimizeAway template is provided to ensure that the optimizing compiler does not eliminate your function or code. Since this feature is used in all of the sample benchmarks and their baseline, it's time overhead is canceled out in the comparisons. You haven't included the definition, just the documentation. I think you're asking for help understanding why it even exis...

 c++                     1 answers                     99 view
 2018-10-22         Patrick

Disturbing order of evaluation

When I work with my favorite containers, I tend to chain operations. For instance, in the well-known Erase–remove idiom:v.erase( std::remove_if(v.begin(), v.end(), is_odd), v.end() );From what I know of the order of evaluation, v.end() (on the rhs) might be evaluated before the call to std::remove_if. This is not a problem here since std::remove* only shuffle the vector without changing its end iterator.But it could lead to really surprising constructs, like for instance (demo):#include <iostream>struct Data{ int v; int value() const { return v; }};auto inc(Data...

 c++                     1 answers                     0 view
 2018-10-22         Edwina

Operator Overloading with template

I am trying to modify the Add function to represent operator overloading.#include <iostream>using namespace std;template <class T>class cpair{public: cpair(T x = 0, T y = 0) { A = x; B = y; } void print() { cout << A << " " << B << endl; } T A, B;};template <class T>void Add(cpair<T> A1, cpair<T> A2, cpair<T> &R){ R.A = A1.A + A2.A; R.B = A1.B + A2.B;}int main(){ cpair<int> A1(4, 5), A2(1, 3), result; Add(A1, A2, result); result.print(); return 0;}I am learning oper...

 c++                     2 answers                     1 view
 2018-10-22         Olivia

The function should return 1 but it is returning 0

The following code takes input x and y and then calls a function. The function is supposed to be called 3 times in which case it will return 1. If, however, the values of x or y decline to very low levels the function won't be called 3 times in which case it will return 0.My input is 3, 22. I can see that the value of t becomes 3 after the function has been called 3 times, but, it returns the value 0 instead of 1 (as seen from the value of i). Can someone explain why this is happening?PS : Some sections of the code have been removed so that we can focus only on the relevant...

 c++                     2 answers                     8 view
 2018-10-22         Valerie

C++ get acces to class variable

Dear StackOverflowers,I am learning to code object-oriented C++. For a project, I'm programming an esp32 using the Arduino core. I have the following problem:I have a class called ULAM, which contains an array of objects of a class called program and an object of a class called screen.class ULAM {private: UlamProgram programs[10]; UlamScreen screen;}the class program has a public variable String nameclass UlamProgram {public: String name;}from a function within screen I want to access the variable String namevoid UlamScreen::programScreen() { tft.println(programs[...

 c++                     1 answers                     11 view
 2018-10-22         Derrick

Cross compiling gRPC using cmake

I'm trying to cross-compile a gRPC using cmake. I actually managed to do it. Unfortunately my method involves tinkering inside CMakeLists.txt. Problem was that, when I was trying to compile gRPC it was using protobuffer he just compiled. It cannot run ARM compiled executables on x86 machine. I managed to compile it by specifying path to protoc and grpc_cpp_plugin manually in gRPCs main CMakeLists.txt. It is dirty and since I would like to include gRPC as submodule I need clean way to do it. Has anyone managed to cross-compile gRPC using cmake? This way should work:Cross-...

 c++                     1 answers                     48 view
 2018-10-22         Gill

How to deploy C++ project with all dependencies?

I am working on a C++ project that requires third-party libraries (boost, poco, etc). I use cmake/make to install the package to an install location and deploy it to the production machine. However, when pushing the app to another machine, the shared libraries are not present on the target machine causing ld errors. Is there a standard way to detect dependencies (i.e. shared libs) and deploy them to the install location along the application? You can try Linux Deploy Qt.I use it for deploying my Qt application written in C++. Apart from Qt, it also puts other non-Qt depe...

 c++                     1 answers                     50 view
 2018-10-22         Vivian

Best practice to include C++ libraries on my project

I am facing some problems related to how to handle C++ projects. I have a set of repositories all of the tracked with git (hosted on gitlab).repo_A: my current projectrepo_B: a library I have created and need to use in repo_AWhich is the best practice to include repo_B in repo_A?.Installing repo_B at system level? And then use repo_B from repo_A by using the CMakelistsAdding repo_B as submodule on repo_AAdding it in the CMakeLists by using something similar to what is explained in the googletest repositorycmake_minimum_required(VERSION 2.8.2)project(googletest-download NONE...

 c++                     1 answers                     53 view
 2018-10-22         Isabel

Iterating over a list of objects c++

Basically I am creating a basic shell program for a class project. I am stuck on iterating through the files/folders within a directory.My error is in the function DisplayDirectoryContents()class Directory {private:map<string, pair<list<Folder>, list<File> > > directoryContents;string directoryPath;public:list<Folder> getFolders() {return directoryContents[directoryPath].first;}list<File> getFiles() {return directoryContents[directoryPath].second;}string getDirectoryPath() {return directoryPath;}Directory() { directoryPath = "root/"; ...

 c++                     2 answers                     11 view
 2018-10-22         Len

EXC_BAD_ACCESS when adding object to array

I am new programming and C++. I am trying to create a Roster of Person objects using an array and then printing the attributes of the People in the Roster.When I attempt to add a Person to the personArray, I am getting an Exception = EXC_BAD_ACCESS (code=1, address=0x0).I think this has to do with the scope of my personArray but I can't seem to figure it out.Here is the code I am using:#include <iostream>#include <sstream>#include <vector>using namespace std;class Person {public: Person(string name, int age); string getName() { return name; ...

 c++                     2 answers                     21 view
 2018-10-22         Emily

Reading json files in C++

I'm trying to read in a JSON file. So far I have focused on using the jsoncpp library. However, the documentation is quite hard to understand for me. Could anyone explain in lay terms what it does? Say I have a people.json which looks like this:{"Anna" : { "age": 18, "profession": "student"}, "Ben" : { "age" : "nineteen", "profession": "mechanic"} }What happens when I read this in? Can I create some sort of data structure people which I can index by Anna and Ben as well as age and profession? What would be the data type of people? I thought it would be ...

 c++                     5 answers                     50 view
 2018-10-22         Sigrid

Animating along an elliptical path in OpenGL

I am trying to make a red circle follow the path of a semi-circle using the DDA algorithm in OpenGL. I almost have it, though the circle is slightly offset on its X-axis, which increases as the angle of the semi-circle increases. Any assistance would be greatly appreciated! Here's my code:scrPt movecircle (scrPt p1, scrPt p2){ scrPt circlePos; float angle, x = p1.x, y = p1.y, vectorX, vectorY; // Get tahe x distance between the two points int dx = p2.x - p1.x, steps; // Get the y distance between the two points int dy = p2.y - p1.y; // Get the length be...

 c++                     1 answers                     81 view
 2018-10-22         Mandel

GTest's EXPECT_EQ giving undefined reference to error

#include <gtest/gtest.h>template<typename T, size_t N>size_t getSize(T (&arr)[N]){ return N; }template<int N>struct ArrayParam { static const int _length = N; int _arr[N];};ArrayParam<3> ap1 = {{1,2,3}};//ArrayParam<4> ap2 = {{1,2,3,4}};class ParamTest: public ::testing::TestWithParam<ArrayParam<3>>{};TEST_P(ParamTest, SizeTest){ ArrayParam<3> param = GetParam(); printf("\nparam._length == %d\n",param._length); //OK printf("\nValue2 == %d\n",ArrayParam<3>::_length); //OK //EXPECT_EQ(param._length,getSize(param....

 c++                     1 answers                     82 view

Page 1 of 6670  |  Show More Pages:  Top Prev Next Last