• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:07
CET 11:07
KST 19:07
  • 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
Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool31Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Potential Updates Coming to the SC2 CN Server Weekly Cups (March 2-8): ByuN overcomes PvT block Weekly Cups (August 25-31): Clem's Last Straw? Weekly Cups (March 9-15): herO, Clem, ByuN win
Tourneys
World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea JaeDong's form before ASL BSL Season 22
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours Small VOD Thread 2.0 IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5339 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
Germany2594 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
RSL Revival
10:00
Season 4: Playoffs Day 2
herO vs MaxPax
Rogue vs TriGGeR
Tasteless384
CranKy Ducklings45
Rex29
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Tasteless 384
ProTech130
Rex 29
StarCraft: Brood War
Sea 19966
Calm 5917
Hyuk 2886
Jaedong 1349
Horang2 1234
Mong 476
Larva 461
Hm[arnc] 427
BeSt 371
actioN 252
[ Show more ]
EffOrt 151
Light 89
Soma 89
Pusan 74
Rush 74
ZerO 56
Yoon 54
Aegong 41
Mind 38
sorry 36
NotJumperer 31
zelot 25
Barracks 25
GoRush 25
Free 25
ToSsGirL 25
hero 21
Noble 18
Last 16
910 16
Terrorterran 13
Bale 12
SilentControl 5
eros_byul 0
Dota 2
XaKoH 1144
XcaliburYe203
Counter-Strike
Stewie2K1051
zeus523
Heroes of the Storm
MindelVK16
Other Games
singsing1811
Fuzer 200
Sick162
ZerO(Twitch)11
Organizations
Other Games
gamesdonequick575
Dota 2
PGL Dota 2 - Main Stream115
Other Games
BasetradeTV51
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH248
• 3DClanTV 23
• CranKy Ducklings SOOP4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• HappyZerGling139
Upcoming Events
BSL
9h 54m
Replay Cast
13h 54m
Replay Cast
22h 54m
Afreeca Starleague
23h 54m
Sharp vs Scan
Rain vs Mong
Wardi Open
1d 1h
Monday Night Weeklies
1d 6h
Sparkling Tuna Cup
1d 23h
Afreeca Starleague
1d 23h
Soulkey vs Ample
JyJ vs sSak
Replay Cast
2 days
Afreeca Starleague
2 days
hero vs YSC
Larva vs Shine
[ Show More ]
Kung Fu Cup
3 days
Replay Cast
3 days
KCM Race Survival
3 days
The PondCast
3 days
WardiTV Team League
4 days
Replay Cast
4 days
WardiTV Team League
5 days
RSL Revival
5 days
Cure vs Zoun
WardiTV Team League
6 days
BSL
6 days
RSL Revival
6 days
ByuN vs Maru
Liquipedia Results

Completed

Jeongseon Sooper Cup
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
CSL 2026 SPRING (S20)
CSL Season 20: Qualifier 1
Acropolis #4
IPSL Spring 2026
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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 © 2026 TLnet. All Rights Reserved.