• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:51
CEST 17:51
KST 00:51
  • 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
[ASL22] Ro8 Preview: In A Tizzy9[ASL22] Ro16 Preview: Holy Diver5[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9
Community News
Weekly Cups (Sep 13-20): herO scores triple2BSL Season 236Weekly Cups (Sep 7-12): SHIN, ByuN, MaxPax double down1StarCraft open world shooter announced at BlizzCon101Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) Weekly Cups (Sep 13-20): herO scores triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool How do you feel about the StarCraft shooter announcement at BlizzCon 2026? The Death of Cheese: From a Professional Cheeser
Tourneys
Stellar Fest TWO the Moon (Dec 16-20) Sparkling Tuna Cup - Weekly Open Tournament 2026 GSTL Announcement RSL Revival: Season 6 - Qualifiers and Main Event RSL goes to London! 2026 Offline Finals Nov 21-22
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[M] (2) Frigid Storage
External Content
Mutation # 544 Double Trouble The PondCast: SC2 News & Results Mutation # 543 Enhanced Defenses Mutation # 542 The Ascended
Brood War
General
BW General Discussion NaDa's Body BSL Season 23 screpdb: new Starcraft reporting tool an AI researcher's take on the ladder bot
Tourneys
[ASL22] Ro8 Day 2 [ASL22] Ro16 Group D [ASL22] Ro8 Day 1 [IPSL] IPSL is Back With Winter 26-27!
Strategy
Cliff Jump Revisited (1 in a 1000 strategy) Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation
Other Games
General Games
Diablo IV Nintendo Switch Thread Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread EVE Corporation
Dota 2
Dota 2 Champions League Season 3 Begins April 25! Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Artificial Intelligence Thread Things Aren’t Peaceful in Palestine All you football fans (soccer)!
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Gaming Intensity, Problemati…
TrAiDoS
38 yo Retired SWE loo…
PurE)Rabbit-SF
Can Bots Beat Pros?? Starcr…
namkraft
[meme] I finally understa…
LUCKY_NOOB
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8012 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
Germany2597 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 18h 10m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
UpATreeSC 292
SteadfastSC 122
CosmosSc2 68
StarCraft: Brood War
Britney 42906
Shuttle 2993
Light 870
BeSt 736
Mini 417
Rush 326
Stork 302
Snow 205
hero 123
Dewaltoss 91
[ Show more ]
Shine 55
Hyun 42
PianO 35
Sexy 31
sorry 29
ToSsGirL 25
HiyA 23
Hm[arnc] 22
Terrorterran 21
Sharp 20
Rock 20
NotJumperer 17
Aegong 16
Dota 2
qojqva2952
Counter-Strike
x6flipin444
ceh9347
Heroes of the Storm
crisheroes398
Other Games
hiko753
B2W.Neo601
Liquid`VortiX227
ArmadaUGS146
Mew2King92
Rex80
QueenE60
Trikslyr11
Organizations
Dota 2
PGL Dota 2 - Main Stream8350
StarCraft 2
IntoTheiNu 659
StarCraft: Brood War
Afreeca ASL 367
StarCraft 2
TaKeTV 51
StarCraft: Brood War
Kim Chul Min (afreeca) 7
[ Show 14 non-featured ]
StarCraft 2
• mYiSmile139
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 6496
• WagamamaTV373
League of Legends
• Nemesis3031
• TFBlade989
Other Games
• Shiphtur125
Upcoming Events
The PondCast
18h 10m
Replay Cast
1d 8h
Korean StarCraft League
2 days
CranKy Ducklings
2 days
GSL
3 days
Yamato Cup
3 days
Replay Cast
4 days
Afreeca Starleague
4 days
Soma vs Jaedong
WardiTV Weekly
4 days
Sparkling Tuna Cup
5 days
[ Show More ]
Afreeca Starleague
5 days
Leta vs Soulkey
PiGosaur Cup
6 days
Kung Fu Cup
6 days
Liquipedia Results

Completed

Super Anchor Qualifying S3
Blizzard Classic Cup 2026
Big Dog Cup 2026 Div 1

Ongoing

ASL Season 22
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - GSA
Calamity Invitational
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSB
Acropolis #5 - GSC
BSL Season 23
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Custodian Cup
Copium Cup
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #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.