« first day (154 days earlier)      last day (2923 days later) » 

04:14
what how did you do that? even ideone cannot print it well
http://ideone.com/1crmtQ
04:45
@Unknown123 I wasn't using an online compiler. But if you must, coliru is more Unicode-friendly: coliru.stacked-crooked.com/a/7e15c2c430dc1e17 (that's what I ran in both compilers)
 
16 hours later…
20:43
Hello, i have a huge problem with my exlipse c++ environment. Can someone help me>
I installed eclipse and added the MinGW compiler to the windows path. Also i changed the to UTF-8 and UNIX. Furthermore I chose as dialect the c++11. When i try to build my projects the binaries wont get created and to_string is still shown as unresolved.
Hi Everyone.. I was exploring on constructor , copy constructor and assignment overloading concepts of c++.. Came across an really interesting output for the below simple program.. Can anybody explain how it works..???
class foo{
public:
foo(){
cout<<"I am Constructor"<<endl;
}
foo(const foo &f){
cout<<"I am copy constructor"<<endl;
}
foo operator =( const foo &f){
cout<<"I am assignment operator"<<endl;
return *this;
}
~foo (){
cout<<"I am destructor"<<endl;
}
};

int main() {
foo f1;
foo f2 =f1;
f2 = f1;
vector <foo> vect;
vect.push_back(f1);
return 0;
}
3 messages moved from Lounge<C++>
1 message moved from Lounge<C++>
Hello
Anybody there ???
nwp
nwp
@ShivarajBhat that is hard to read, maybe you should use the code formatting
or even better post it on coliru.stacked-crooked.com so people can play with it
@Schbabako Several MinGW versions are outdated and std::to_string doesn't work there, I suggest using MinGW-w64 which is currently maintained.
20:59
ok i will try. I already installed many compilers....
nwp
nwp
@ShivarajBhat which part is unclear?
@nwphow the order of destructor is called..
i see the order for the above code as below..
I am Constructor
I am copy constructor
I am assignment operator
I am copy constructor
I am destructor
I am copy constructor
I am destructor
I am destructor
I am destructor
That's the actual output. What's the expected output?
I am Constructor --- for foo f1;
I am copy constructor --- for f2=f1;
I am assignment operator --- for f2 =f1;
I am copy constructor --- for vect.push_back(f1);
I am destructor ------- >?????
I am copy constructor ------------> ???
I am destructor -------------> ????
I am destructor ----- for destructing f2 object
I am destructor ---- for destucting f1 object
21:05
ok
@ShivarajBhat the temporary copied and destroyed when you do push_back, and the destruction of the stored element inside std::vector
@ShivarajBhat foo f2 =f1; may look like assignment, but it's not. It does copy construction. To get assignment, you'd have to do something like foo f2; f2 = f1;
correct.. first 3 lines of output i understand clearly..
after that is a bit confusion ...
@ShivarajBhat Okay. It's just the question marks you're asking about?
nwp
nwp
@JerryCoffin I think the core question is why push_back requires a temporary
yess..
please.
if i remove two lines in main ()
still copy constructor is called twice in the output screen..
Say suppose
int main() {
foo f1;
foo f2 =f1;
f2 = f1;
//vector <foo> vect;
//vect.push_back(f1);
return 0;
}
output is ---->
I am Constructor
I am copy constructor
I am assignment operator
I am copy constructor
I am destructor
I am destructor
I am destructor
@milleniumbug Very nicely done.
thanks a lot.. it cleared all my doubt...
@milleniumbug thank you so much...
hey, still the binaries wont get created.
I really dont know what else to do
I reinstalled MinGW, exlipse and used also PE windows parser. I added this c++11 into the settings
21:29
@JerryCoffin spent too much time wondering why had the spurious temporary appeared, when it turned out that operator= returns by value
@Schbabako have you checked that the std::to_string works when you invoke the compiler outside of IDE?
When I start a new project and use to_string in there it works. I create a new source file with a new header . The header includes string and in the source i use the to_string statement. Bot are included in my main. But i doesnt work anymore
21:50
I dont know what to show you. I just try to import an existing project by copy pasting the header and source files into a new c++ project. When i try to build it then it shows me that to_string and stoi cant be resolved
20 mins ago, by milleniumbug
@Schbabako have you checked that the std::to_string works when you invoke the compiler outside of IDE?
how do i do that ?
you take all the files, and run g++ -std=c++11 file1.cpp file2.cpp file3.cpp fileN.cpp -o output_executable_name.exe on them
I dont know how to do that. WHat do you mean by "I take all the files" and where shall i "run" the command?
you run the command prompt
you cd /d C:\directory\path\where\your\project\is\located
and then you run the command above with passing all the source files to it
21:57
ok working on it
also include the headers or just the cpp?
source
only source files
ok
it also says stoi and to_string was not returned in this scope
declared*
so it's not a problem with your IDE configuration
it could be a problem with your compiler so you should then compile a simple source file which does nothing but call these functions
#include <string>
int main() { std::to_string(42); std::stoi("42"); }
22:30
it doesnt work
it gives me an error
i installed all necessary compiler files.
which one you tried
(post the link to the site you downloaded it from)
also: what error do you get
I guess it's something like "to_string not declared" but I want to be sure
Sourceforge.net/projects/mingw-w64/
for the second attempt it gave me the error "undefined reference to 'winmain@16'
i will restart my computer
i will be back in a sec
@Schbabako seriously? are you compiling the file with the contents I posted above?
because this suggests you have a different problem altogether
I have a Snake-class which has a dynamic array of BodyPart-objects, I need to initialize each of them, but I don't know how.
Tried this: (in Snake.h, I have "private: BodyPart* body;")
this->body = new BodyPart[this->parts](xStart, yStart);

xStart an yStart are floats passed into the constructor of the Snake-object
I got the error:
"an array cannot be initialized with a parenthesized initializer"
no one likes new
use std::vector
22:40
I don't either. But this is a requirement.
Hopefully after January the professors will let us use vectors finally.
uni assignment? oh well, universities being bad at C++, as usual
2
i redid it. I said just it was not declared in this scope now
it*
@Schbabako run where g++ in your command prompt
c:\minGW\bin\g++.exe
is the response
22:43
is this your newly downloaded mingw-w64
@milleniumbug
yes
i can redo it
but shouldnt change to much
oh, and run g++ --version
g++ <GCC> 5.0.3
5.3.0
sorry
which version do you have?
6.2
but std::to_string should be available in 5.3 too
but it doesnt even work like this in the command prompt..
22:47
@JackOfBlades can't do this with new. Usual solution is to use std::vector. Alternatively, if your BodyParts are default constructible, you could use new BodyPart[size] and then assign to the every element in a loop
I'll fiddle around for a bit, see what happens. Thanks.
when i made a new project in eclipse and included all the files into my main it worked.
at some point it stopped creating the binaries when i cleaned the project but to_string could be resolved. when i try to import the project or just import the source and header files from a working project the "to_string" function could not be resolved,.
@milleniumbug The singular form of new isn't entirely bad. It's really only the array form of new that's irredeemably evil and should absolutely never be used.
23:33
and even when i have that project which is empty eclipse doesnt create the binaries

« first day (154 days earlier)      last day (2923 days later) »