• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 15:03
CET 21:03
KST 05:03
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread ZeroSpace Megathread The Perfect Game
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1708 users

The Big Programming Thread - Page 255

Forum Index > General Forum
Post a Reply
Prev 1 253 254 255 256 257 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2013-02-24 17:19:41
February 24 2013 17:18 GMT
#5081
... previous page
There is no one like you in the universe.
supereddie
Profile Joined March 2011
Netherlands151 Posts
February 24 2013 18:02 GMT
#5082
On February 25 2013 01:50 nakam wrote:
[MySQL]
Lets say I have the following table
*snip*

I now want the sum of the score for each player at that date so that the result becomes:
*snip*

It's almost like a SUM(score) and GROUP BY playerid, datetime.

How do I achieve this in MySQL? I know it is possible and very easy if I process this in php and I know how to do that, it's just that I'd like to do it with SQL if possible.

You don't want a sum, you want a running total. Just use your favorite search engine on how to do a running total in MySQL.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
nakam
Profile Joined April 2010
Sweden245 Posts
February 24 2013 18:12 GMT
#5083
On February 25 2013 03:02 supereddie wrote:
Show nested quote +
On February 25 2013 01:50 nakam wrote:
[MySQL]
Lets say I have the following table
*snip*

I now want the sum of the score for each player at that date so that the result becomes:
*snip*

It's almost like a SUM(score) and GROUP BY playerid, datetime.

How do I achieve this in MySQL? I know it is possible and very easy if I process this in php and I know how to do that, it's just that I'd like to do it with SQL if possible.

You don't want a sum, you want a running total. Just use your favorite search engine on how to do a running total in MySQL.

That's it! Searched like crazy but I couldn't figure out what it was called in english. Thx.
TL Local Timezone Script - http://www.teamliquid.net/forum/viewmessage.php?topic_id=277156
Sky101
Profile Blog Joined May 2003
United States1758 Posts
February 24 2013 21:22 GMT
#5084
Is anyone familiar with the Magento platform? I could use some help, your time will be compensated, please pm me, thanks!
Peter, Dang, pm me!!!
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-02-24 23:24:19
February 24 2013 23:23 GMT
#5085
On February 25 2013 02:18 Kambing wrote:
Show nested quote +
On February 25 2013 02:07 darkness wrote:
I have a rather simple presentation problem.

My output is like this:

number(space)number(space)
number(space)number(space)
number(space)number(space)

However, an online check program wants output in without the 2nd space:
number(space)number
number(space)number
number(space)number

The variable is not unique. Any suggestions?

Let me know if you need more info.


Assuming that you are generating this sequence in a loop, this is an example of a fencepost loop. Your for-loop likely looks like this:


For each number n:
print n + " "


This generates the former sequence rather than the latter sequence. You can think of the for-loop as a stamp that repeatedly generates "number(space)". The trick is to recognize that this stamp cannot possibly generate the form on its own because of the special case at the end which has no space.

Your only recourse is to factor this special case out of loop:


For each number n except the last:
print n + " "
print the last number


This is called a fencepost loop because the problem is analogous to laying down fenceposts and wire.


|--|--|--|


There is one extra fencepost (n+1 overall) that you must account for when using n pieces of wire. The code ends up being easier to read if, rather than special casing the last post, you special case the first post and change the pattern accordingly:


print the first number
For each number n starting from the second:
print " " + n


Thanks. I ended up with using a temp variable to achieve the same result.

I'm slowly but surely starting to understand C a bit more on the other hand. Pointers make more sense to me now. Also heap too.


waxypants
Profile Blog Joined September 2009
United States479 Posts
Last Edited: 2013-02-25 02:42:59
February 25 2013 02:33 GMT
#5086
On February 25 2013 01:01 Arnstein wrote:
Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes?

Also, I seem to have misunderstood operator overloading syntax.

This is added to the previously seen code:
+ Show Spoiler +


const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2);

const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2)
{
double matrise[1][1];
matrise[0][0] = matrise1.getValue(0,0) + matrise2.getValue(0,0);
matrise[0][1] = matrise1.getValue(0,1) + matrise2.getValue(0,1);
matrise[1][0] = matrise1.getValue(1,0) + matrise2.getValue(1,0);
matrise[1][1] = matrise1.getValue(1,1) + matrise2.getValue(1,1);

}


This doesn't give any compiler errors, but it does give a warning since I don't have a return on the +operator.

Also, when I test it by making two matrices, a and b, then c = a+b;, I get this:

+ Show Spoiler +

Program received signal: “EXC_BAD_INSTRUCTION”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
(gdb)


When you declare an array, you give its size. This is different from indexing. If you want it 2x2 in size, you give [2][2].

Treat "warnings" as errors unless you perfectly understand why there is a warning and why it doesn't matter (you should probably try to clean up all warnings anyway though).

The + operator takes in two matrices and returns a result matrix. Clearly you are not doing that (and you recognize it), so how do you expect it to work? I believe the correct thing is to create a new matrix "Matrix2x2 result;" And use result.setValue to initialize it, and then return result. I'm not 100% sure about this though because I don't really program much in true C++, but I think it will set your variable "c" to a shallow copy of the result, which sounds like what you would want.

edit:
Someone please tell me if I'm right or wrong, but I believe for more complex classes (ones that allocate memory), you would need to implement a destructor and copy constructor. And in that case, +operator would invoke the copy constructor to copy result to c (in the c = a + b example) and then call the destructor on result.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
February 25 2013 03:45 GMT
#5087
On February 25 2013 06:22 Sky101 wrote:
Is anyone familiar with the Magento platform? I could use some help, your time will be compensated, please pm me, thanks!

Not familiar. Played around with it. Should be easy to work with for simple stuff with no coding background.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2013-02-25 04:04:18
February 25 2013 03:50 GMT
#5088
On February 24 2013 22:35 Arnstein wrote:
+ Show Spoiler +


#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[1][1];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();

};



int main()
{
Matrix2x2 a;
a.printMatrix();
a.setValue(0.0,0.0,1.0);
a.printMatrix();

}

Matrix2x2::Matrix2x2()
{
matrix.setValue(0, 0, 1.0);
matrix.setValue(0, 1, 0.0);
matrix.setValue(1, 0, 0.0);
matrix.setValue(0, 1, 1.0);
}


void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(double x, double y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}







I get really many errors on this one. Why doesn't this work?


Okay so I'll just point out some stuff.

I could be completely wrong, but I do not believe it is possible to access with a double like that. Even from logic, since doubles aren't ever the same number twice, it doesn't seem to make sense, unless there's some auto-correction going on.

Your setValue function should take the arguments, (int, int, double) thus.

Similarly, your getValue function should take the arguments (int, int).



You should also be using [2][2] for your matrix size. That will properly initialize a 2x2 array.



From what kambling mentioned in the previous page, your print has an extra space because you don't handle the syntax there well at all.

You can follow his method, but really, since your array is so small, unless you have plans to make it scalable, you should just write it in two lines of std::couts.


Similarly, if you have plans of making it scalable, in the class constructor use the nested for loops instead of hard-coding it.

(edit: technically you can't really make it scalable, so I mean in the copy&paste sense, haha)



You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of.


And finally, like AKnopf mentioned, while your syntax is technically correct, you should always be using this->member or this.member when accessing member variables or functions, because this clears ambiguity at times when you're debugging, like now.




On February 25 2013 11:33 waxypants wrote:
Show nested quote +
On February 25 2013 01:01 Arnstein wrote:
Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes?

Also, I seem to have misunderstood operator overloading syntax.

This is added to the previously seen code:
+ Show Spoiler +


const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2);

const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2)
{
double matrise[1][1];
matrise[0][0] = matrise1.getValue(0,0) + matrise2.getValue(0,0);
matrise[0][1] = matrise1.getValue(0,1) + matrise2.getValue(0,1);
matrise[1][0] = matrise1.getValue(1,0) + matrise2.getValue(1,0);
matrise[1][1] = matrise1.getValue(1,1) + matrise2.getValue(1,1);

}


This doesn't give any compiler errors, but it does give a warning since I don't have a return on the +operator.

Also, when I test it by making two matrices, a and b, then c = a+b;, I get this:

+ Show Spoiler +

Program received signal: “EXC_BAD_INSTRUCTION”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
(gdb)


When you declare an array, you give its size. This is different from indexing. If you want it 2x2 in size, you give [2][2].

Treat "warnings" as errors unless you perfectly understand why there is a warning and why it doesn't matter (you should probably try to clean up all warnings anyway though).

The + operator takes in two matrices and returns a result matrix. Clearly you are not doing that (and you recognize it), so how do you expect it to work? I believe the correct thing is to create a new matrix "Matrix2x2 result;" And use result.setValue to initialize it, and then return result. I'm not 100% sure about this though because I don't really program much in true C++, but I think it will set your variable "c" to a shallow copy of the result, which sounds like what you would want.

edit:
Someone please tell me if I'm right or wrong, but I believe for more complex classes (ones that allocate memory), you would need to implement a destructor and copy constructor. And in that case, +operator would invoke the copy constructor to copy result to c (in the c = a + b example) and then call the destructor on result.




Yes, you are right about the sizes, but I don't believe the copy constructor is required.

I don't think Arnstein is really clear in what he wants to do with this overloaded operator.

What you've done is created a new matrix (with incorrect sizes), then you attempt to set values in this matrix to the sum of the two matrices you've put as arguments.

But then you do nothing with this final matrix as matrix you created is not returned, and it doesn't modify the class matrix either. So nothing happens, and you should be getting array out of bounds errors.

Except your overload function has incorrect syntax.

You want



const MyClass MyClass::operator+(const MyClass &other)





I'm also going to say I'm not sure why you're using pointers to classes in your arguments. I don't think that's necessary (or valid).
There is no one like you in the universe.
waxypants
Profile Blog Joined September 2009
United States479 Posts
February 25 2013 04:08 GMT
#5089
On February 25 2013 12:50 Blisse wrote:
Show nested quote +
On February 24 2013 22:35 Arnstein wrote:
+ Show Spoiler +


#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[1][1];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();

};



int main()
{
Matrix2x2 a;
a.printMatrix();
a.setValue(0.0,0.0,1.0);
a.printMatrix();

}

Matrix2x2::Matrix2x2()
{
matrix.setValue(0, 0, 1.0);
matrix.setValue(0, 1, 0.0);
matrix.setValue(1, 0, 0.0);
matrix.setValue(0, 1, 1.0);
}


void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(double x, double y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}







I get really many errors on this one. Why doesn't this work?


You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of.

...

I'm also going to say I'm not sure why you're using pointers to classes. I don't think that's necessary (or valid).


I'm quite sure you don't need a destructor for this class because it doesn't allocate any memory. There is no "may want to implement a destructor", you either need one to delete some extra stuff or you don't.

Of course you can use pointers to classes. "this" is a pointer to the current instantiation of the class whose instance method you are in.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2013-02-25 04:25:04
February 25 2013 04:15 GMT
#5090
On February 25 2013 13:08 waxypants wrote:
Show nested quote +
On February 25 2013 12:50 Blisse wrote:
On February 24 2013 22:35 Arnstein wrote:
+ Show Spoiler +


#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[1][1];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();

};



int main()
{
Matrix2x2 a;
a.printMatrix();
a.setValue(0.0,0.0,1.0);
a.printMatrix();

}

Matrix2x2::Matrix2x2()
{
matrix.setValue(0, 0, 1.0);
matrix.setValue(0, 1, 0.0);
matrix.setValue(1, 0, 0.0);
matrix.setValue(0, 1, 1.0);
}


void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(double x, double y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}







I get really many errors on this one. Why doesn't this work?


You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of.

...

I'm also going to say I'm not sure why you're using pointers to classes. I don't think that's necessary (or valid).


I'm quite sure you don't need a destructor for this class because it doesn't allocate any memory. There is no "may want to implement a destructor", you either need one to delete some extra stuff or you don't.

Of course you can use pointers to classes. "this" is a pointer to the current instantiation of the class whose instance method you are in.



meh, might as well have thrown it out there. I'm rusty on my C++ and I'm not sure if you really need to or not without invoking new. And I know it's valid (idk why I thought it wasn't), I'm just wondering if that's necessary for that operator+ since he was trying to return a new instance?

Wait nevermind that was dumb. Scratch thattt.
There is no one like you in the universe.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 25 2013 07:30 GMT
#5091
On February 25 2013 12:50 Blisse wrote:
Show nested quote +
On February 24 2013 22:35 Arnstein wrote:
+ Show Spoiler +


#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[1][1];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();

};



int main()
{
Matrix2x2 a;
a.printMatrix();
a.setValue(0.0,0.0,1.0);
a.printMatrix();

}

Matrix2x2::Matrix2x2()
{
matrix.setValue(0, 0, 1.0);
matrix.setValue(0, 1, 0.0);
matrix.setValue(1, 0, 0.0);
matrix.setValue(0, 1, 1.0);
}


void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(double x, double y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}







I get really many errors on this one. Why doesn't this work?


Okay so I'll just point out some stuff.

I could be completely wrong, but I do not believe it is possible to access with a double like that. Even from logic, since doubles aren't ever the same number twice, it doesn't seem to make sense, unless there's some auto-correction going on.

Your setValue function should take the arguments, (int, int, double) thus.

Similarly, your getValue function should take the arguments (int, int).



You should also be using [2][2] for your matrix size. That will properly initialize a 2x2 array.



From what kambling mentioned in the previous page, your print has an extra space because you don't handle the syntax there well at all.

You can follow his method, but really, since your array is so small, unless you have plans to make it scalable, you should just write it in two lines of std::couts.


Similarly, if you have plans of making it scalable, in the class constructor use the nested for loops instead of hard-coding it.

(edit: technically you can't really make it scalable, so I mean in the copy&paste sense, haha)



You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of.


And finally, like AKnopf mentioned, while your syntax is technically correct, you should always be using this->member or this.member when accessing member variables or functions, because this clears ambiguity at times when you're debugging, like now.




Show nested quote +
On February 25 2013 11:33 waxypants wrote:
On February 25 2013 01:01 Arnstein wrote:
Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes?

Also, I seem to have misunderstood operator overloading syntax.

This is added to the previously seen code:
+ Show Spoiler +


const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2);

const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2)
{
double matrise[1][1];
matrise[0][0] = matrise1.getValue(0,0) + matrise2.getValue(0,0);
matrise[0][1] = matrise1.getValue(0,1) + matrise2.getValue(0,1);
matrise[1][0] = matrise1.getValue(1,0) + matrise2.getValue(1,0);
matrise[1][1] = matrise1.getValue(1,1) + matrise2.getValue(1,1);

}


This doesn't give any compiler errors, but it does give a warning since I don't have a return on the +operator.

Also, when I test it by making two matrices, a and b, then c = a+b;, I get this:

+ Show Spoiler +

Program received signal: “EXC_BAD_INSTRUCTION”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
(gdb)


When you declare an array, you give its size. This is different from indexing. If you want it 2x2 in size, you give [2][2].

Treat "warnings" as errors unless you perfectly understand why there is a warning and why it doesn't matter (you should probably try to clean up all warnings anyway though).

The + operator takes in two matrices and returns a result matrix. Clearly you are not doing that (and you recognize it), so how do you expect it to work? I believe the correct thing is to create a new matrix "Matrix2x2 result;" And use result.setValue to initialize it, and then return result. I'm not 100% sure about this though because I don't really program much in true C++, but I think it will set your variable "c" to a shallow copy of the result, which sounds like what you would want.

edit:
Someone please tell me if I'm right or wrong, but I believe for more complex classes (ones that allocate memory), you would need to implement a destructor and copy constructor. And in that case, +operator would invoke the copy constructor to copy result to c (in the c = a + b example) and then call the destructor on result.




Yes, you are right about the sizes, but I don't believe the copy constructor is required.

I don't think Arnstein is really clear in what he wants to do with this overloaded operator.

What you've done is created a new matrix (with incorrect sizes), then you attempt to set values in this matrix to the sum of the two matrices you've put as arguments.

But then you do nothing with this final matrix as matrix you created is not returned, and it doesn't modify the class matrix either. So nothing happens, and you should be getting array out of bounds errors.

Except your overload function has incorrect syntax.

You want



const MyClass MyClass::operator+(const MyClass &other)





I'm also going to say I'm not sure why you're using pointers to classes in your arguments. I don't think that's necessary (or valid).


You are right, I have no idea what I'm doing, haha!

I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this?
The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong.

+ Show Spoiler +
/*
* Oving 5 del 2.cpp
* Ovinger
*
* Created by Arnstein Kleven on 2/24/13.
* Copyright 2013 __MyCompanyName__. All rights reserved.
*
*/

#include "Oving 5 del 2.h"
#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[2][2];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();
const Matrix2x2 operator +(const Matrix2x2 &other);
};




int main()
{
Matrix2x2 a;
Matrix2x2 b;


}

Matrix2x2::Matrix2x2()
{

setValue(0, 0, 1.0);
setValue(0, 1, 0.0);
setValue(1, 0, 0.0);
setValue(1, 1, 1.0);
}


void Matrix2x2::setValue(int x, int y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(int x, int y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}



const Matrix2x2 Matrix2x2::operator +(const Matrix2x2 &other)
{
Matrix2x2 c;
double x0 = this.getValue(0,0) + &other.getValue(0,0);
c.setValue(0,0, x0);
return c;

}
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
WindWolf
Profile Blog Joined July 2012
Sweden11767 Posts
February 25 2013 07:39 GMT
#5092
On February 25 2013 16:30 Arnstein wrote:
You are right, I have no idea what I'm doing, haha!

I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this?
The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong.

+ Show Spoiler +
/*
* Oving 5 del 2.cpp
* Ovinger
*
* Created by Arnstein Kleven on 2/24/13.
* Copyright 2013 __MyCompanyName__. All rights reserved.
*
*/

#include "Oving 5 del 2.h"
#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[2][2];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();
const Matrix2x2 operator +(const Matrix2x2 &other);
};




int main()
{
Matrix2x2 a;
Matrix2x2 b;


}

Matrix2x2::Matrix2x2()
{

setValue(0, 0, 1.0);
setValue(0, 1, 0.0);
setValue(1, 0, 0.0);
setValue(1, 1, 1.0);
}


void Matrix2x2::setValue(int x, int y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(int x, int y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}



const Matrix2x2 Matrix2x2::operator +(const Matrix2x2 &other)
{
Matrix2x2 c;
double x0 = this.getValue(0,0) + &other.getValue(0,0);
c.setValue(0,0, x0);
return c;

}


Just a tip from another ESL coder. Name files with English names for the sake of consistency. It will make your life easier in the long run since all code "is in English".
EZ4ENCE
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 25 2013 08:00 GMT
#5093
On February 25 2013 16:39 WindWolf wrote:
Show nested quote +
On February 25 2013 16:30 Arnstein wrote:
You are right, I have no idea what I'm doing, haha!

I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this?
The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong.

+ Show Spoiler +
/*
* Oving 5 del 2.cpp
* Ovinger
*
* Created by Arnstein Kleven on 2/24/13.
* Copyright 2013 __MyCompanyName__. All rights reserved.
*
*/

#include "Oving 5 del 2.h"
#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[2][2];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();
const Matrix2x2 operator +(const Matrix2x2 &other);
};




int main()
{
Matrix2x2 a;
Matrix2x2 b;


}

Matrix2x2::Matrix2x2()
{

setValue(0, 0, 1.0);
setValue(0, 1, 0.0);
setValue(1, 0, 0.0);
setValue(1, 1, 1.0);
}


void Matrix2x2::setValue(int x, int y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(int x, int y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}



const Matrix2x2 Matrix2x2::operator +(const Matrix2x2 &other)
{
Matrix2x2 c;
double x0 = this.getValue(0,0) + &other.getValue(0,0);
c.setValue(0,0, x0);
return c;

}


Just a tip from another ESL coder. Name files with English names for the sake of consistency. It will make your life easier in the long run since all code "is in English".



Thanks, will do this from now on!

Also, any tip you guys can give me, please do! I want to become a good programmer!
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
nunez
Profile Blog Joined February 2011
Norway4003 Posts
February 25 2013 08:24 GMT
#5094
On February 25 2013 17:00 Arnstein wrote:
Show nested quote +
On February 25 2013 16:39 WindWolf wrote:
On February 25 2013 16:30 Arnstein wrote:
You are right, I have no idea what I'm doing, haha!

I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this?
The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong.

+ Show Spoiler +
/*
* Oving 5 del 2.cpp
* Ovinger
*
* Created by Arnstein Kleven on 2/24/13.
* Copyright 2013 __MyCompanyName__. All rights reserved.
*
*/

#include "Oving 5 del 2.h"
#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[2][2];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();
const Matrix2x2 operator +(const Matrix2x2 &other);
};




int main()
{
Matrix2x2 a;
Matrix2x2 b;


}

Matrix2x2::Matrix2x2()
{

setValue(0, 0, 1.0);
setValue(0, 1, 0.0);
setValue(1, 0, 0.0);
setValue(1, 1, 1.0);
}


void Matrix2x2::setValue(int x, int y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(int x, int y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}



const Matrix2x2 Matrix2x2::operator +(const Matrix2x2 &other)
{
Matrix2x2 c;
double x0 = this.getValue(0,0) + &other.getValue(0,0);
c.setValue(0,0, x0);
return c;

}


Just a tip from another ESL coder. Name files with English names for the sake of consistency. It will make your life easier in the long run since all code "is in English".



Thanks, will do this from now on!

Also, any tip you guys can give me, please do! I want to become a good programmer!


they just want to be able to reverse engineer your code more easily! obfusk8 your cøde to the max.

you might want to do a re-read on reference, de-reference operators and this keyword.
this line looks a bit faulty!
double x0 = this.getValue(0,0) + &other.getValue(0,0);
conspired against by a confederacy of dunces.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 25 2013 08:36 GMT
#5095
Yes, that's the line that is messing up! I don't know how to do this inside of a operator overload function, so I just copied some stuff from the header in the class, and also tried to copy something from the book. In the book you had leftHandSide and rightHandSide, but it didn't seem like these were declared. Then how does C++ know which one they mean?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2013-02-25 09:00:03
February 25 2013 08:58 GMT
#5096
On February 25 2013 17:36 Arnstein wrote:
Yes, that's the line that is messing up! I don't know how to do this inside of a operator overload function, so I just copied some stuff from the header in the class, and also tried to copy something from the book. In the book you had leftHandSide and rightHandSide, but it didn't seem like these were declared. Then how does C++ know which one they mean?


i am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question!

you've got all the info you need to solve that exercise lined up in just the right order the institution you are attending deems best. i think you need to trace back a couple of exercises and make sure you understand what the words in the code you are compiling mean (in this context)!
conspired against by a confederacy of dunces.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 25 2013 09:02 GMT
#5097
Alright, will do
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
Savi[wOk]
Profile Blog Joined August 2012
United States81 Posts
Last Edited: 2013-02-25 11:36:26
February 25 2013 11:35 GMT
#5098
Out of curiosity.
Since computers are made out of code, why don't windows computers come with something like a "C compiler"?
I heard that the Commodore 64 and the Atari 8-bit came with compilers.
It feels like buying a music sequencing software, and all you can do is listen to music, put together loops, and insert samples. While being unable to compose your own music.
Lets play starcraft
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
Last Edited: 2013-02-25 11:55:53
February 25 2013 11:52 GMT
#5099
On February 25 2013 20:35 Savi[wOk] wrote:
Out of curiosity.
Since computers are made out of code, why don't windows computers come with something like a "C compiler"?
I heard that the Commodore 64 and the Atari 8-bit came with compilers.
It feels like buying a music sequencing software, and all you can do is listen to music, put together loops, and insert samples. While being unable to compose your own music.


Computers aren't made out of code...

Commodore 64 and Atari 8-bit were before the internet, where you can go online and download visual studio express for free and write / compile programs with a nice IDE.

Then there are all the other compilers you can get like gcc in MiniGW, also for free.

Considering most users have no use for a compiler, and those who do are going to know how to download it, it doesn't make sense to bloat an already bloated OS with additional features like this considering it would require a full installation of VS, or microsoft to make MSBUILD separate, which makes no sense because you just get something like MiniGW if you want to do something like that.

For something like Linux it makes sense to have compilers on it, its generally only used by devs / serious tech heads who are significantly more likely to use it. Plus you do more stuff on the command line in linux so having a compiler you can use on the command line is useful and keeping with how people use the OS, plus its open source so making a full suite like VS would be impossible.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2581 Posts
February 25 2013 14:08 GMT
#5100
On February 25 2013 20:52 adwodon wrote:
Commodore 64 and Atari 8-bit were before the internet, where you can go online and download visual studio express for free and write / compile programs with a nice IDE.

Also, back in those days, writing the code that ran on your hardware was a very common way of interacting with a computer. In those days, for example, it was common for a computer magazine to come with a game in it in the form of code to be copied by hand and compiled. Now general-purpose commercial software is available to do every common task, and writing code is a very rare way of interacting with a computer.
The frumious Bandersnatch
Prev 1 253 254 255 256 257 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 57m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 613
SteadfastSC 234
IndyStarCraft 98
Railgan 55
StarCraft: Brood War
Britney 14946
Calm 2419
Shuttle 615
Larva 268
firebathero 168
Dewaltoss 114
Dota 2
Gorgc6322
420jenkins367
capcasts8
Counter-Strike
fl0m5689
chrisJcsgo51
kRYSTAL_28
Heroes of the Storm
Liquid`Hasu319
Khaldor150
Other Games
Grubby2487
Beastyqt594
RotterdaM127
Sick123
C9.Mang096
ArmadaUGS86
QueenE63
Mew2King60
Trikslyr58
Organizations
Other Games
Algost 1
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• StrangeGG 56
• Reevou 12
• Dystopia_ 1
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• 80smullet 17
• FirePhoenix6
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV577
• lizZardDota260
League of Legends
• TFBlade549
Other Games
• imaqtpie940
• Shiphtur205
Upcoming Events
Replay Cast
3h 57m
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
WardiTV 2025
1d 15h
SC Evo League
1d 16h
BSL 21
1d 23h
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
2 days
OSC
2 days
[ Show More ]
BSL 21
2 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
PiGosaur Monday
5 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
WardiTV 2025
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.