• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 04:05
CET 10:05
KST 18:05
  • 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
Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational14SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win1Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)25
StarCraft 2
General
Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win StarCraft 2 not at the Esports World Cup 2026 herO wins SC2 All-Star Invitational PhD study /w SC2 - help with a survey! Oliveira Would Have Returned If EWC Continued
Tourneys
China Business Email List – Connect with Verified General Managers Mailing List – Connect with Key $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open!
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 510 Safety Violation Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained
Brood War
General
[ASL21] Potential Map Candidates BGH Auto Balance -> http://bghmmr.eu/ Which foreign pros are considered the best? Gypsy to Korea Fantasy's Q&A video
Tourneys
[Megathread] Daily Proleagues Azhi's Colosseum - Season 2 Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026!
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Lost love spell caster in Spain +27 74 116 2667
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread YouTube Thread Russo-Ukrainian War Thread Canadian Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1542 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
Germany2590 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
Replay Cast
09:00
Rongyi Cup S3 - Playoffs Day 1
CranKy Ducklings17
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 150
StarCraft: Brood War
Hyuk 775
Jaedong 382
Killer 198
JulyZerg 190
Hyun 73
Mong 72
Hm[arnc] 72
Noble 54
Pusan 54
soO 53
[ Show more ]
Shuttle 49
Flash 47
Backho 43
zelot 27
HiyA 26
Sacsri 24
GoRush 13
Bale 10
Soma 8
Dota 2
NeuroSwarm113
XcaliburYe8
League of Legends
JimRising 1160
C9.Mang0355
Other Games
Liquid`RaSZi784
WinterStarcraft482
ceh9463
olofmeister276
Happy267
singsing204
Mew2King102
oskar53
Organizations
Other Games
gamesdonequick890
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1483
• Stunt500
Upcoming Events
RongYI Cup
1h 55m
Clem vs TriGGeR
Maru vs Creator
WardiTV Invitational
4h 55m
PiGosaur Cup
15h 55m
Replay Cast
23h 55m
RongYI Cup
1d 1h
herO vs Solar
WardiTV Invitational
1d 4h
The PondCast
1d 23h
HomeStory Cup
3 days
Korean StarCraft League
3 days
HomeStory Cup
4 days
[ Show More ]
Replay Cast
4 days
HomeStory Cup
5 days
Replay Cast
5 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-01-26
OSC Championship Season 13
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025

Upcoming

Escore Tournament S1: W6
Escore Tournament S1: W7
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
LiuLi Cup: 2025 Grand Finals
HSC XXVIII
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
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.