ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
can anyone look over this really quick and tell me some mistakes i made
Code:
#include <iostream>
using namespace std;
class windowLnkList{
public:
windowLnkList(windowLnkList *whereToPush = 0){
////////////////
///////Note: that above means the class after(Pnext)
////// and below means the class before(Pprev)
////////////////
//This is where a chain link is inserted
//(1)This is where we add references to the above/below class to this one
Pprev = (whereToPush != 0) ? (whereToPush) : (0);//Link to "object below's" location, if exists
Pnext = (whereToPush != 0) ? (whereToPush->Pnext) : (0);//Link to "object above's" location, if exists
//(2)This is where we add references to this class to the above/below classes
(Pnext != 0) ? (Pnext->Pprev = this) : (0);//link object above, if app, to this location
(whereToPush != 0) ? (whereToPush->Pnext = this) : (0);//link object below, if app, to this location
}
~windowLnkList(){
if(Pprev != 0)//if this isn't the first item in the list
Pprev->Pnext = Pnext;
if(Pnext != 0)//if this isn't the last item in the list
Pnext->Pprev = Pprev;
}
void display(){
cout << "Pnext: " << &Pnext << endl;
cout << "this: " << this << endl;
cout << "Pprev: " << &Pprev << endl << endl;
if(Pnext != 0){
Pnext->display();}
}
windowLnkList *Pprev;
windowLnkList *Pnext;
};
int main(int argc, char *argv){
windowLnkList class1;
//class1.display();
windowLnkList class2(class1);
//class2.display();
windowLnkList class3(class1);
class1.display();
}
yeah, but I think the (0) should be changed to NULL to prevent any value from being stored there, and I personally like the ( ) ? : way of making if statements. Potato PotAto.
Ya, you definitly want to use NULL, there is a big different between something pointing to 0 and something pointing to NULL.
As far as the () ? :, it sucks for readability when statements get more complex then simple if-then-else statements which is why few people use it. In general most new guides to C and C++ tell people to shy away from them in general. I remember a professor I had a in college telling us if he saw those operators in our code we would be repeating his class.
It was his feeling that those, along with goto's, we completely unexceptable in 99.9% of all cases.
I complied and ran this code with a return statement and NULL's and it seams to work fine for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.