« first day (1459 days earlier)      last day (1385 days later) » 

7:03 AM
Why is the following code wrong?:
#include <array>
#include <iostream>
#include <vector>

void foo() {
    std::array<int, 2> b[3];
    for (int i = 0; i < 3; i++) {
        int a;
        std::cin >> a;
        b[i] = { a,i };
    }
    std::vector<std::array<int, 2>> ans;
    int a = 10, b = 20;
    ans.push_back(std::array<int, 2>{ a,b });
}

int main() {
    foo();
    return 0;
}
the problem is in ans.push_back(std::array<int, 2>{ a,b });
 
because you have two variables named "b"
std::array<int, 2> b[3];
int a = 10, b = 20;
 
Goodness
Can I get any more dumb? XD
 
 
2 hours later…
9:07 AM
I am trying to compile this c++ repository on MacOS, and I'm getting the following errors when I run make. Can someone enlighten me on what the two errors below mean?
Scanning dependencies of target uocte_autogen
[  3%] Automatic MOC for target uocte
[  3%] Built target uocte_autogen
Scanning dependencies of target uocte
[  6%] Building CXX object CMakeFiles/uocte.dir/uocte_autogen/mocs_compilation.cpp.o
In file included from /tmp/uocte/build/uocte_autogen/mocs_compilation.cpp:3:
In file included from /tmp/uocte/build/uocte_autogen/UVLADIE3JM/moc_main.cpp:10:
In file included from /tmp/uocte/build/uocte_autogen/UVLADIE3JM/../../../src/main.hpp:36:
/tmp/uocte/build/uocte_autogen/UVLADIE3JM/../../../src/io/exportJpeg.hpp:13:52: error: no member named '__cx
 
seems like it's just broken, second one seems be fixed here: bitbucket.org/uocte/uocte/pull-requests/1/…
and you can just remove the "__cxx11::" that's just unnecessarily specific
 
9:23 AM
1) is this a pointer to the array?
#include <string.h>
int main(int argc, char *argv[])
{
    char    abc[27];
    char    *ptr = abc;
    strcpy(abc, "abcdefgxyz");
     /*
     * What are the types and values of expressions:
     *

     * 1. abc
     * 2. *abc
     * 3. abc[2]
     * 4. &abc[3] //&abc[3] = abc + 3*sizeof(char)
     * 5. abc+4
     * 6. *(abc+5) + 20000  //h  long long x = int * 1LL * int
     * 7. abc[10] //'\0'
     * 8. abc[12] //memset ()
     * 9. &ptr //char**
     */
     return 0;
}
5) is this a pointer to abc[4] or the variable itself?
 
In C++ abc itself is an array, but it can be implicitly converted to a pointer, which it is in the case of "char *ptr = abc;" and "abc+4"
also I forget the details for C, but they're slightly different than C++
 
so abc is an array not a pointer, strange
but abc+4 is a pointer
 
yes, but it gets converted to a pointer in many many cases
 
ok
thanks
 
9:32 AM
whats the advantage of using Entity ent2(); to create a class?
do you use this yourself?
 
Entity ent(); I don't ever use because it's a recipe for the most vexing parse
if you have to, use "Entity ent{};"
 
theres so many ways to initialise an object which i didnt realise until now
which version of object initialisation should i prefer?
also when should you intialise an object with new in c++?
 
10:02 AM
0
Q: Dynamic Object vs Non dynamic object in C++

PermianWhen do you want to use a dynamically allocated object such as, https://leetcode.com/problems/design-twitter/, Your Twitter object will be instantiated and called as such: Twitter* obj = new Twitter(); obj->postTweet(userId,tweetId); vector param_2 = obj->getNewsFeed(userId); obj->follow(followe...

 
10:49 AM
@PeterT Sorry, I had to take a call.
@PeterT How do I clone that pull request? It doesn't look like it has been merged otherwise I would just clone source code in that repo.
 
just put the "void" in front of the function signature, it's not like it's a huge amount of changes
just manually change the files in your copy I'd say
 
11:11 AM
@PeterT thanks, I clone the repository that created the pull request, that fixed the second error. As for the 1st error I fixed it by deleting "cxx11::" just as you suggested.
@PeterT Now I'm getting different errors:
1 warning generated.
[ 37%] Building CXX object CMakeFiles/uocte.dir/src/converter.cpp.o
/tmp/C/src/converter.cpp:213:24: error: call to 'abs' is ambiguous
            double d = std::abs(m_scan.size[1] / m_scan.tomogram.height() * (o2(x, y) - o1(x, y))); // thickness in mm
                       ^~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h:132:6: note: candidate function
int      abs(int) __pure2;
         ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/stdlib.h:111:44: note: candidate function
 
hello. i am having issues with understanding the move operator in C++. I have a vector that is allocated on the stack. now i need to move that vector to a pointer to a vector that has been allocated on the heap. is that possible ?
 
I'm thinking my version of c++ on MacOS is probably much newer than the one specified in the source code I'm compiling.
 
i tried this outputData = std::move(&inputData);
but this does not seem to work.
 
@MyWrathAcademia well that call is probably just wrong, from the calls it looks like it feeds an unsigned number to abs, but you can just be explicit and cast it to a specific signed type
 
inputData is an object that has been allocated on the heap.
outputData is a unique_ptr that has been allocated on the heap
 
11:15 AM
or if it's a floating point number use fabs
double d = std::fabs(m_scan.size[1] / m_scan.tomogram.height() * (o2(x, y) - o1(x, y)));
 
sorry inputData is an object that has been allocated on the stack
 
*outputData = std::move(inputData); // if you have already constructed outputData
outputData.reset(new std::vector<type_here>(std::move(inputData))); //otherwise
 
@PeterT Thanks. In the above code, do you think the compiler error is only for the statement double d = std::abs(m_scan.size[1] / m_scan.tomogram.height() * (o1(x, y))), or is the error also for lines like int abs(int) __pure2;?
 
@PeterT yes thanks the second solution compiles just fine
 
@MyWrathAcademia what? that line isn't from the code you need to worry about, that's just a note to explain the previous error
 
11:21 AM
i had an empty outputData initially. and i resized it with the size of inputData. that did not compile
 
@PeterT Oops just caught that.
 
but the second solution you gave me compiled just fine
 
@PeterT It seems that c++ does not recognize fabs:
1 warning generated.
[ 37%] Building CXX object CMakeFiles/uocte.dir/src/converter.cpp.o
/tmp/C/src/converter.cpp:213:29: error: no member named 'fabs' in namespace 'std'
            double d = std::fabs(m_scan.size[1] / m_scan.tomogram.height() * (o2(x, y) - o1(x, y))); // thickness in mm
                       ~~~~~^
/tmp/C/src/converter.cpp:344:33: error: no member named 'fabs' in namespace 'std'
                double d = std::fabs(m_scan.size[1] / m_scan.tomogram.height() * (o1(x, y))); // thickness in mm
 
does the file include <cmath> ?
 
@PeterT No, this is what the top of the file looks like:
#include "converter.hpp"

namespace Converter
{
 
11:33 AM
then add the cmath include
 
Is `<cmath> called a header?
Or is it a class?
 
yes it's just

#include <cmath>
 
I don't know c++
 
it's a header file
 
But I guess this is one way to learn it.
 
11:34 AM
it's the same in C, it's just that most of the C ones have the *.h suffix
 
Okay, thanks. So is a header file equivalent to a class in C#/ Java?
 
no
A header file is just a file that by convention contains definitions for functions, structures and/or classes, it's not like some structured import like newer languages typically have
 
@PeterT Thanks, I see that a header is used for one or more classes. A header sounds similar to a library of helper methods except that the library also includes classes and structs in it. Great. Why are functions hidden in a separate header when you can define them in the same class?
I mean is there any advantage to defining functions, structures and/or classes in a header?
 
A header file is by convention just used to share definitions in multiple files.

You can either do

//a.cpp
int abs(int);
int somefunc(){abs(2);}

//b.cpp
int abs(int);
int somefunc2(){abs(3);}

or you can have:

//definition.h
#pragma once
int abs(int);

//a.cpp
#include "definition.h"
int somefunc(){abs(2);}

//b.cpp
#include "definition.h"
int somefunc2(){abs(3);}
that way you don't have to copy the full definition of every function/class you use into every file that uses it
 
11:50 AM
@PeterT I see, that's very interesting. I wonder why other C family languages like C# and Java didn't adopt headers. There must be an alternative in those languages, that I'm not aware of.
 
@MyWrathAcademia the header model is outdated, it's a simple copy-paste include model from like the 1960s
even c++ is trying to modernize it with modules
structured includes/imports are better in every conceivable way
 
@PeterT Are the modules in newer c++ versions the same as modules in Java and Python (I'm not sure C# has modules at all)?
 
they're trying to be something like it
 
@PeterT cool. I'm glad c++ is not afraid of changing to become a bit more like more modern languages.
Recently I was considering learning rust instead of c++ but I've come across so many instances where knowing C++ would have benefited me greatly that I am reconsidering. For example, I tried to use C# OpenCV wrappers such as OpenCVSharp, EmguCV etc. and they were impossible to get working due to extremely vague exceptions.
Computer vision is not the only reason I'm interested in C++.
Is C++ used a lot in robotics?
I'm interested in gaming too, but I know C# (to an extent) so I'm fine where game programming is concerned.
 
Feels that way.
Well OpenCV can be really rough, for debugging purposes I've had to look at the sources multiple times
 
12:02 PM
Yeah tell me about it. Getting help is not easy as well, for the OpenCV wrappers at least.
So after including the cmath header file this is what the first 10 lines of the file looks like:
% head converter.cpp
#include "converter.hpp"
#include cmath

namespace Converter
{
    int load(const QString &path, oct_subject** mySubject)
    {
        if (path == "")
            return -1;
        else
 
it's "#include <cmath>" not "#include cmath"
 
@PeterT Oh right, thanks.
@PeterT I corrected the include directive. Now I'm getting a fatal error:
1 warning generated.
[ 37%] Building CXX object CMakeFiles/uocte.dir/src/converter.cpp.o
[ 40%] Building CXX object CMakeFiles/uocte.dir/src/io/jpge.cpp.o
/tmp/C/src/io/jpge.cpp:15:10: fatal error: 'malloc.h' file not found
#include <malloc.h>
         ^~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/uocte.dir/src/io/jpge.cpp.o] Error 1
make[1]: *** [CMakeFiles/uocte.dir/all] Error 2
make: *** [all] Error 2
@PeterT This means malloc.h is missing. Is malloc.h a user defined header or a standard c++ header?
 
that's the wrong header, it's supposed to be #include <stdlib.h
malloc.h is some implementation specific thing
 
Why were you trying to include malloc.h anyway?
 
it's not his code
 
12:13 PM
@PeterT #include <stdlib.h> is already in the file. Here's what the first 20 lines of the file is:
// jpge.cpp - C++ class for JPEG compression.
// Public domain, Rich Geldreich <richgel99@gmail.com>
// v1.01, Dec. 18, 2010 - Initial release
// v1.02, Apr. 6, 2011 - Removed 2x2 ordered dither in H2V1 chroma subsampling method load_block_16_8_8(). (The rounding factor was 2, when it should have been 1. Either way, it wasn't helping.)
// v1.03, Apr. 16, 2011 - Added support for optimized Huffman code tables, optimized dynamic memory allocation down to only 1 alloc.
//                        Also from Alex Evans: Added RGBA support, linear memory allocator (no longer needed in v1.03).
 
then just remove the malloc include
 
@Mgetz It's this code
@PeterT Right.
@Peter by the way, is it necessary to wipe the build directory before running make again?
 
no, usually it's not
make will see if files changed
 
Okay, thanks. So far I've been wiping the build directory, and re-running cmake then followed by make. Just to be safe.
Almost there...
This is the latest error:
/tmp/C/src/render_fundus.cpp:17:10: fatal error: 'GL/glew.h' file not found
#include <GL/glew.h>
         ^~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/uocte.dir/src/render_fundus.cpp.o] Error 1
make[1]: *** [CMakeFiles/uocte.dir/all] Error 2
make: *** [all] Error 2
Do I delete that include or replace it with something else?
I think glew is quite important.
 
you replace with some ifdefs for mac, let me check what it was
 
12:21 PM
Thanks.
 
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

I think
maybe if it explicitly uses some glew functions you might need to just install glew
via homebrew or something like it
 
It's worth noting that apple's support for OpenGL is deprecated and buggy at best
they won't fix things
 
yeah it seems to just use opengl functions, you can just remove the "glewInit();" call I think
 
@Mgetz thanks for the heads up.
@PeterT So what changes now we know that apple does not use OpenGL?
 
Well you can continue to use it until apple removes it
 
12:32 PM
I see only one instance of glewInit(); in the file
 
then assume you're going to have to panic and replace it with Metal
although there is moltengl.com/moltengl
 
@Peter do I still replace #include <GL/glew.h> or just delete glewInit();?
 
you still need the opengl includes
for all the other gl*() functions in that file
 
@Peter I replaced the glew includes. This is how the first 50 lines of the cpp file look like:
/*
 * Copyright 2015 TU Chemnitz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 
you didn't delete the glewInit();
 
12:43 PM
@PeterT And that's why I get this error:
/tmp/C/src/render_fundus.cpp:44:5: error: use of undeclared identifier 'glewInit'
    glewInit();
 
then delete it :P
 
haha
I forgot how fun compiling from source is. The file /tmp/C/src/render_mip.cpp also had `#include <GL/glew.h> so I just repeated the same solution for the last error
How often do you come across super nested for loops like this:
void denoise(volume<T> &img)
  {
    unique_ptr<T []> n(new T[img.width() * img.height() * img.depth()]);
    T *p = n.get(), *q = img.data();

    vector<T> v;
    v.reserve(5 * 5);
    for (int z = 0; z != int(img.depth()); ++z)
    {
      int min_z = -min(0, z), max_z = min(0, int(img.depth()) - 1 - z);
      for (int y = 0; y != int(img.height); ++y)
      {
        int min_y = -min(1, y), max_y = min(1, int(img.height()) -  1 - y);
        for (int x = 0; x != int(img.width); ++x)
        {
Surely there's another way.
 
pretty often when writing/reading filter kernels
well when the filter kernel has some properties you can sometimes put it into the frequency domain and transform it into a multiplication
but there's not generalizable way to do it differently that I know
but this looks like a median filter, you can't solve that one in the fequency domain
 
1:07 PM
@PeterT interesting, I don't know what frequency domain and filter kernel are. May be I'll get to learn them in the future if I ever need to know about them
@PeterT Success!
52 warnings generated.
[100%] Linking CXX executable bin/uocte
[100%] Built target uocte
 
now it'll probably just crash at runtime :P
 
@PeterT Waat?? If it does, I'll quit, and go do something easier like run for president.
Does make install just install an executables directly into your path?
 
it hast some default location, you can change it by setting some variable during configration
PREFIX_PATH or something like it
for cmake it's CMAKE_INSTALL_PREFIX
 
thanks. I'll refrain from adding the uocte executable to my path (for now).
 
you can probably just try to run the executable without installing anyway
I don't think they'll have some sophisticated deployment process
 
1:19 PM
I'll try to run the executable when I figure out how to use the program.
How do I run this program? There's no instructions in the readme at bitbucket.org/bitbucket_at_kalvdans/uocte/src/master. I'm guessing c++ is like Java and C# in that program execution starts and ends in the Main method? So I've looked in /tmp/C/src/main.cpp to see whether the Main method has a parameter for a filename string but I can't see any such parameter.
 
it's just some Qt ui app, just start it without any parameters
 
nwp
argv in main is that parameter, but QCoreApplication::arguments also exists. Though typically GUI applications don't use command line arguments.
 
@PeterT thanks, I just ran it with ./uocte and I get the following GUI window but it is totally unresponsive. What gives?
 
use the menu at the top
 
@nwp Thanks, I've found argv in main:
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);

    main_window w;
    w.show();

    return app.exec();
}
 
nwp
1:33 PM
Yup. That's where the parameters end up if any. And they are being passed to QApplication.
 
@PeterT That's wierd, at first the menu at the top was unresponsive, until I read your message and tried again.
Its working now, yeehaww
@PeterT @nwp @Mgetz the great news is that this program gives the same black and white picture I posed two days ago:
yesterday, by MyWrathAcademia
user image
Above is mine. Below is theirs:
The only difference is theirs is a bit lighter. Probably because of they went further with adjusting the luminance.
 
Maybe just applied srgb gamma
 
1:57 PM
@PeterT is gamma brightness? srgb is for a colored image but that image with the green box at the centre is black and white (i.e. monochrome).
 
srgb has gamma corrections for each seperate RGB channel, right, but that still results in a different total gamma even for greyscale images
any I would assume that the measurement output of scientific sensors is mostly linear and not gamma corrected
 
@PeterT you would be very very wrong
it's definitely corrected all the time
 
I've been known to be very wrong
 
@Mikhail can give glorious detail on just how bad scientific sensors can be.. and might even know about this format
 
@PeterT Thanks for explaining. Is it correct to think that I can implement a gamma correction by premultiplying each color channel by some decimal point number between 0 and 1?
 
2:06 PM
@MyWrathAcademia it could actually be a curve
the file may have a separate gamma histogram
 
@Mgetz Wow :0. I am lost.
@Mgetz Even more lost.
 
An image histogram is a type of histogram that acts as a graphical representation of the tonal distribution in a digital image. It plots the number of pixels for each tonal value. By looking at the histogram for a specific image a viewer will be able to judge the entire tonal distribution at a glance. Image histograms are present on many modern digital cameras. Photographers can use them as an aid to show the distribution of tones captured, and whether image detail has been lost to blown-out highlights or blacked-out shadows. This is less useful when using a raw image format, as the dynamic range...
Histogram equalization is a method in image processing of contrast adjustment using the image's histogram. Histogram equalization is the best method for image enhancement. It provides better quality of images without loss of any information. == Overview == This method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values. Through this adjustment, the intensities can be better distributed on the histogram. This allows for areas of lower local contrast to gain a higher contrast. Histogram equalization accomplishes...
actually the last link has a really good example for you
 
Comparing my image and their mage, to go from my image to their image you have to view my image from the x direction and flip it in the y direction, or in other words, rotate my image anti-clockwise along the z axis and then flip it in the y direction.
@Mgetz Thanks, I'll bookmark that. When would you use this image histogram?
 
@MyWrathAcademia literally whenever you display an image
almost every image you see is adjusted in some way
At a minimum:
In color management, an ICC profile is a set of data that characterizes a color input or output device, or a color space, according to standards promulgated by the International Color Consortium (ICC). Profiles describe the color attributes of a particular device or viewing requirement by defining a mapping between the device source or target color space and a profile connection space (PCS). This PCS is either CIELAB (L*a*b*) or CIEXYZ. Mappings may be specified using tables, to which interpolation is applied, or through a series of parameters for transformations. Every device that captures or...
 
nwp
2:22 PM
@Mgetz That is a lot of text to say "normalize the image to make the minimum 0 and the maximum 255".
 
Given that you're using Heidlberg images... and they are deep into that sort of thing... it would be odd for them not to include correction information
@nwp not quite, you may actually do more than that to make things more visible
or to adjust for sensor or display issues
 
I need a second pair of eyes to help me confirm this. In the following output by that program, is the top left colored image just a colored version of the bottom image?
 
nwp
2:41 PM
No, they did more than just color it. The top one has vertical lines, the bottom one doesn't.
It's pretty clearly the same object being filmed, but the images don't show the same information about the object.
 
the top one could just be stacked slices of the bottom thing
 
3:05 PM
@nwp Thanks. Well that's being the scope of what I'm doing. I'll settle for what I have now, which is the bottom image
@PeterT The thing though is that I only found one slice which is the bottom image.
Any way, I'm gonna start learning c++ sooner rather than later. First I have to finish getting through C# and Java. Can you guys recommend any good books or guides I could read to learn c++ fast? I don't know how different constructs like variables, etc. are in c++ compared to C# or Java, so may be it is better that any books you recommend skip these beginner stuff.
 
nwp
3:21 PM
I would not recommend skipping beginner stuff. The beginner stuff is tricky because C# and Java use pretty much the same keywords and syntax, but the meaning is different.
For people coming from Java I recommend to never ever use new and to also not use inheritance if at all possible. It'll avoid most mistakes that Java programmer tend to make in C++.
The tour was meant for people wanting to quickly jump into C++. Maybe that's for you.
 
 
3 hours later…
6:18 PM
@nwp excellent recommendation. That book is written by the creator of c++. I look forward to reading all of it.
 
 
1 hour later…
7:47 PM
Node* head=new Node(0); why use dynamic allocation here? (vs the opposite)
Node(int val) {
        this->val=val;
        next=NULL;
    }
why use "this" here? why not do
Node(int val) {
val=val;
next=NULL;
}
 
in "val=val" the left and the right side are the same variable
 
 
2 hours later…
9:28 PM
are there any new approaches on newest C++'s for specifying any object, such as void* and Boost::Any?
 
nwp
9:46 PM
std::any exists, but I haven't found it very useful.
It turns out if you don't know the type of an object you can't really do anything with it.
 
 
2 hours later…
user13783520
11:50 PM
This isn't really C++ it's more C but do I need to fclose files if I call abort()?
 
user13783520
If they were opened like this fopen(path, "r")
 

« first day (1459 days earlier)      last day (1385 days later) »