Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Technology (https://www.graalians.com/forums/forumdisplay.php?f=54)
-   -   Coding in C++ (https://www.graalians.com/forums/showthread.php?t=26365)

Jatz 11-27-2014 02:32 PM

Sigh.

Powder 11-27-2014 02:43 PM

Quote:

Posted by Jatz (Post 520757)
Sigh.

Whatever, GraalOnline's game engine is scipted under C++...
You can't take that away. :angry:

hosler 11-27-2014 03:39 PM

Using an entire namespace is perfectly fine. You guys make me sick.

Jatz 11-27-2014 04:12 PM

No it's not, it's horrible practice.

hosler 11-27-2014 04:13 PM

it's fine and no one cares either way. using all of it vs individual parts does not affect performance. also it will only cause problems when you are using more than one namespace that share function names, which is a problem i almost never run into.

Jatz 11-27-2014 04:29 PM

There's an example in the link tricxta posted a few posts above...

PHP Code:

using namespace std

alongside the Qt library.

Qt has a member "endl" and so does "std", therefore when outputting endl to std::cout, it spat out some weird number. As far as c++ goes, using an entire namespace is a horrible idea, and is frowned upon by most professional developers.

hosler 11-27-2014 05:13 PM

Oh. I must confess that I did not know this thread was about becoming a professional c++ coder.
Still, using a full namespace does not matter until it matters, and at that point you know enough to deal with it.

mallard 11-27-2014 06:45 PM

Quote:

Posted by Jatz (Post 520796)
There's an example in the link tricxta posted a few posts above...

PHP Code:

using namespace std

alongside the Qt library.

Qt has a member "endl" and so does "std", therefore when outputting endl to std::cout, it spat out some weird number. As far as c++ goes, using an entire namespace is a horrible idea, and is frowned upon by most professional developers.

Would it be better to always type out the namespace:: instead? I've been doing that but dunno if that's stupid or not. Haven't needed to type them out often enough where it's annoying.

Jatz 11-28-2014 12:44 AM

I usually type the namespace name because they're often very short so it doesn't matter. The best idea is to do that, or use the specific parts of the namespace that you need.

Quote:

Posted by hosler (Post 520815)
Oh. I must confess that I did not know this thread was about becoming a professional c++ coder.
Still, using a full namespace does not matter until it matters, and at that point you know enough to deal with it.

Why intentionally teach someone a bad habit that they'll have to unlearn later?

Fysez 11-29-2014 07:56 AM

Quote:

Posted by hosler (Post 520768)
Using an entire namespace is perfectly fine. You guys make me sick.

Agreed that it is fine.

However, I'm one of those people who type std::cout << "chvfhdgjb" << std::endl;

I'm not sure why this namespace argument is even a controversy, it really doesn't matter which way you use it unless you get some uncommon error for it, in which case you can look it up online for a fix.

Motrox 12-02-2014 04:30 AM

Thanks for the help and advice Tricxta and Jatz :)
I'm still a little confused on the issue on namespaces though.
Currently working on making a project list I can get working on. If you guys have any suggestions for good beginner projects such as the calculator. Which in fact did help me learn a Ton over the past two weeks that would be great.

Tricxta 12-02-2014 08:49 AM

Quote:

Posted by Motrox (Post 522438)
Thanks for the help and advice Tricxta and Jatz :)
I'm still a little confused on the issue on namespaces though.
Currently working on making a project list I can get working on. If you guys have any suggestions for good beginner projects such as the calculator. Which in fact did help me learn a Ton over the past two weeks that would be great.

Start learning about object oriented(OO) concepts like polymorphism and inheritance. You can practice both using the following exercise.

Consider a list that can store multiple types of shapes.

Using this one list, store a square, triangle and circle. Iterate over that list and print out the area and name of each shape.
Example pseudocode of populating such a list might be

PHP Code:

List<Shapeshapes = List;
shapes.addCirclexyradius ) )
shapes.addsquarex1y1x2y2x3y3x4y4) )
shapes.addtrianglex1y1x2y2x3y3 ) ) 

To demonstrate an understanding of inheritance in this exercise, have both the triangle and square object extend a polygon object.
You can use this formula for the area:
http://i.imgur.com/Zc1g5lu.png

Some links to get you started result from some simple google searches:
http://www.tutorialspoint.com/cplusp...nheritance.htm
http://stackoverflow.com/questions/2...l-methods-in-c

If this exercise seems a bit daunting, other nice features to look at include generics(templates) and operator overloads.

Jatz 12-03-2014 04:56 AM

Quote:

Posted by Tricxta (Post 522475)
PHP Code:

List<Shapeshapes = List;
shapes.addCirclexyradius ) )
shapes.addsquarex1y1x2y2x3y3x4y4) )
shapes.addtrianglex1y1x2y2x3y3 ) ) 


That won't compile.
Also if you're looking for a basic dynamic array type, they're called std::vector's in c++.

PHP Code:

std::vector<Shapeshapes;
shapes.push_back(Circle(xyradius))
shapes.push_back(Square(x1y1x2y2x3y3x4y4))
shapes.push_back(Triangle(x1y1x2y2x3y3)) 


Tricxta 12-03-2014 10:29 AM

Quote:

Posted by Jatz (Post 522766)
That won't compile.
Also if you're looking for a basic dynamic array type, they're called std::vector's in c++.

PHP Code:

std::vector<Shapeshapes;
shapes.push_back(Circle(xyradius))
shapes.push_back(Square(x1y1x2y2x3y3x4y4))
shapes.push_back(Triangle(x1y1x2y2x3y3)) 


I said and gave 'rough' pseudocode for a reason... Researching libraries yourself is all part of the learning experience. Stop trying to make me look bad son.

Fysez 12-04-2014 05:33 AM

Quote:

Posted by Tricxta (Post 522475)
Start learning about object oriented(OO) concepts like polymorphism and inheritance. You can practice both using the following exercise.

Consider a list that can store multiple types of shapes.

Using this one list, store a square, triangle and circle. Iterate over that list and print out the area and name of each shape.
Example pseudocode of populating such a list might be

PHP Code:

List<Shapeshapes = List;
shapes.addCirclexyradius ) )
shapes.addsquarex1y1x2y2x3y3x4y4) )
shapes.addtrianglex1y1x2y2x3y3 ) ) 

To demonstrate an understanding of inheritance in this exercise, have both the triangle and square object extend a polygon object.
You can use this formula for the area:
http://i.imgur.com/Zc1g5lu.png

Some links to get you started result from some simple google searches:
http://www.tutorialspoint.com/cplusp...nheritance.htm
http://stackoverflow.com/questions/2...l-methods-in-c

If this exercise seems a bit daunting, other nice features to look at include generics(templates) and operator overloads.

All of the above will confuse any new programmers.
If you're all about "learning on your own," why are you not about "learning sequential steps"?

If he didn't know how to pass parameters (a,b), there's no way he's going to learn pushing back objects with a bunch of variables not defined within the provided pseudo-code within that one reply.

He should really be taking a look at C++ tutorials online where they list steps, not going from "Hello World" straight to "Use objective programming to 'add' shapes with variables for a parameter not given the basic usage for."

-----------------------------------------------

I suggest that if you want to learn how to use C++, you should start with basic (yet fun) programming. Not console programming (borrriinnnggg...)
Lazy Foo has some great tutorials for C++ with SDL so they teach you how to make little 2D programs.

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php
Go ahead and click the Operating System you're currently using (windows, mac, Linux) and then select your C++ compiler (Code::Blocks, Dev-C++, Microsoft Visual Studio) and learn the fun way -- One that intrigues your mind.

Quote:

Posted by Tricxta (Post 522809)
I said and gave 'rough' pseudocode for a reason... Researching libraries yourself is all part of the learning experience. Stop trying to make me look bad son.

If I was new, looking at your whole "List" and "add" would lead me to the wrong path.
I would *probably* literally think that was correct programming and it would confuse me.
If you want to give him a learning experience, showing him a basic "push_back" function is not giving him an entire piece of code. He probably won't know what it is right off the bat, and therefore research it a bit.
Or at least use it for future references.


All times are GMT. The time now is 05:05 PM.

Powered by vBulletin/Copyright ©2000 - 2026, vBulletin Solutions Inc.