Sci@phy 97 Posting Whiz in Training

You should check your microphone. It can sometimes be a problem (conflicts with compiler for c++)

chococrack commented: R O F L @ microphone compiler issues +1
Sci@phy 97 Posting Whiz in Training

while( chioce != 'n' );} should actually be: } while( chioce != 'n' ); Have a nice coding :)

Sci@phy 97 Posting Whiz in Training

I tried to count lines to see which one is line 39, and I managed it

case 'I' : case 'i ' :

Notice that second 'i ', do you see a difference between:

'i'
'i '

First is valid, second is invalid!
Change that first

William Hemsworth commented: Well spotted :) +4
Sci@phy 97 Posting Whiz in Training

Reason is that sstr is set to false AFTER trying to read after EOF. So first you read last item, it's ok, when while sees no error, continues, but you can't read more, so x is assigned to last good reading (last number) AND then sstr is set to FALSE!

You need this: while (sstr>>x){//do stuff with x}

Alex Edwards commented: And I thought it was because the input and output flags weren't on - good deduction! +4
Sci@phy 97 Posting Whiz in Training

  1. First you write code in some text editor. It doesn't matter what editor, it could even be notepad.
    Then you have to compile that code.
    Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. read for more
    Compilation error is therefore something that occured during this phase, most likely syntax error (misspelled some function name, or trying to do something that C doesn't allow)

    So, after compilation, you have object files. In simple programs you have only one object file, so it's difficult to understand need for it (why not just build everything at once?).
    But if you have more different files that you want to merge into one program, first you have to compile every single one into object.
    Then it's linker's job to take all object files and to make executable out of it.
    Linker error is most likely definition/declaration error (you can have function defined in one file, and declared in another. If these two aren't identical linker error occurs).

    Runtime error 99% of the time has to do with evil horrible pointers. It happens at the time program is working, and therefore, the mistake cannot be located so easily.
    Mostly has to do with program …

Salem commented: Nicely put +22
Aia commented: Nice effort. +10
devnar commented: Very well explained. Thanks +1
Sci@phy 97 Posting Whiz in Training

*cough*
Dev-Cpp

THIS compiled ok on dev-cpp:

int main()
{
    DWORD   dwThreadId;
    HANDLE  myThread; 
    void *ptr=NULL;
    
    myThread = CreateThread( 
            NULL,                   
            0,                       
            MyThreadFunction,      
            ptr,           
            0,                      
            &dwThreadId);  

    while(1){
             Sleep(3);
             std::cout << "main";
             } 
    std::cin.get();
    return 0;
}

notice the void* ptr; I suspect problem is in your "HELLO", not in dwThreadId

[edit]And Narue's code compiles on Dev :)[/edit]

Sci@phy 97 Posting Whiz in Training

The while loop won't work properly, eof is unsafe to use in looping.
This is better:

while (getline(locationtemp, line)){
         numbers[x++] = strtod(line);
}
Freaky_Chris commented: Thanks, always wanting to know new things about stability +1
Sci@phy 97 Posting Whiz in Training

Hi gunjan,

Can you please tell me what is the difference between void function(int*d); and void function(int &d); both above are function declarations and both we do the changes to the original variable passed to the function. Then what is the exact difference.

Thanks in advance

The first one is "passing arguments to pointers". In that way, you can change original variable!
Second one is "passing arguments as references".
You cannot do that in C, C always passes arguments by value (yes, even if you use pointers, but then it passes pointer as value, not original value pointed by pointer :) )

So, the first one is ok in C and C++
Second one is only C++

devnar commented: Nicely put. :) +1
Sci@phy 97 Posting Whiz in Training
while(soldiers.size()==1)

This while statement is ill

Sci@phy 97 Posting Whiz in Training

Are you sure this code works:

ll = queue.ll;

'll' is under private section, right? I'm not sure if you can access it.
Here's my code example if it helps:

//operators
//=
Complex& Complex::operator=(Complex const& aCplx){
    if (this != &aCplx){
        mNum.Im = aCplx.getIm();
        mNum.Re = aCplx.getRe();
    }
    return *this;
}
chunalt787 commented: thanks for trying to help +1
Sci@phy 97 Posting Whiz in Training

>void Montecarlo(void);
>{

What's that semicolon doing there? :)

Salem commented: Easy money :) +22
Sci@phy 97 Posting Whiz in Training

I made slight adjustment:

sky.erase(sky.begin()+x);

More on: http://www.cplusplus.com/reference/string/string/erase.html

EDIT: oh yes, x <= sky.size() is wrong, should be x < sky.size()

Sky Diploma commented: Thanks a lot +1
Sci@phy 97 Posting Whiz in Training

I don't see why there should be any difference. When you write:

void MyClass Func (const MyClass f)
//or even simply:
const MyClass f(some_MyClass_obj);

And let's say we call Func:

Func(some_other_MyClass_obj);

What happens? First let's see what happens in a function:
1. We put in a Func "some_other_MyClass_obj".
2. Program calls constructor to construct "f", a local object inside Func
3. Constructor is checking what are you giving to him. He is checking if "some_other_MyClass_obj" is of type const MyClass or simply MyClass, and then calls proper constructor function.
He doesn't care about line "const MyClass f", because after the "f" is constructed, it will be given const-ness.
4. f is made, and is given his const-ness.


OK, what happens in your recent functions, I'll try to explain.
You have a member function doSomething. That function takes MyClass as argument, and it can change it.
Of course you get error when you try to change f inside your non-member function, that's because f is const! But the important thing is that the const-ness is given AFTER constructor (it's obvious, because constructor HAS to change object!)
And the only thing that distincts your two constructors (for post before) is that one accepts one type of argument, and the other one accepts other type of argument.

VernonDozier commented: helpful +7
Sci@phy 97 Posting Whiz in Training

If you want to be able to write

something = 4 + var;

You have to overload once more operator+.

First, declare it as friend of class, and then write it like:

Array<T> operator+ (const float f, Array<T> myVal);

That's because if you define operator+ as a member of class it is interpretting:
val + 3;
as:
val.operator+(3);
So if you write:
3 + val;
it is interpretted as:
3.operator+ //it's clearly rubbish

monkey_king commented: Very helpfull +1
Sci@phy 97 Posting Whiz in Training

It's a long shot, but maybe while optimizing compiler got rid of unneeded functions and code in library?

Salem commented: Yes, except it's the linker, not the compiler. +21