Bench's Profile
Reputation: 844
Master
- Group:
- Expert
- Active Posts:
- 2,334 (1.11 per day)
- Joined:
- 20-August 07
- Profile Views:
- 15,592
- Last Active:
Dec 18 2012 06:00 PM- Currently:
- Offline
Previous Fields
- Country:
- GB
- OS Preference:
- Who Cares
- Favorite Browser:
- Who Cares
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 200
- Expert In:
- C/C++
Latest Visitors
-
Michael26 
30 Mar 2013 - 12:26 -
ButchDean 
11 Feb 2013 - 16:27 -
modi123_1 
01 Feb 2013 - 15:52 -
raghav.nagana... 
31 Dec 2012 - 04:35 -
Mirslr 
25 Dec 2012 - 21:40
Posts I've Made
-
In Topic: Exam: concepts, need some clarification
Posted 21 Oct 2012
FrozenSnake, on 20 October 2012 - 11:39 PM, said:A data type also provides you:Data type: A data type tells us what values a variable can contain. For example, an int can only contain integers; if the programmer would enter a number with decimals the decimals would be truncated. For example would 1.1 be 1.
- Information about the sizeof (in bytes) for an an object of that data type in memory
- An interface to objects of that type (operators form part of an object's interface as much as constructors, member functions, etc)
FrozenSnake, on 20 October 2012 - 11:39 PM, said:However re-use of a function isn't necessary. Sometimes functions are simply used to break larger chunks of code down into smaller ones. A shorter definition of 'function' would be a named block of codeFunction: A snippet of code that is used to solve the same problem several times in different parts in the program without having to re-solve it.
FrozenSnake, on 20 October 2012 - 11:39 PM, said:C++ has two types of polymorphism. The type you're describing here is known as Dynamic polymorphism (at runtime). a.k.a "late binding" or "dynamic binding"Polymorphism: Polymorphism is when we use a function without knowing which class it belongs too. Example on this is in the Invaders game we made, for example when we are doing collision detection. We fetch i:s x- and y-coordinates and j:s x- and y-coordinates. But we do not know if x is a ship, bullet or enemy and the same applies for j. This is handled by the program. These functions doesn’t have to behave the same as the mother class function, it has to have the same “head” but the body can be different.
C++ additionally includes the concept of static polymorphism (polymorphism at compile time); which is more commonly used under the umbrella of Template Metaprogramming.
Both static and dynamic polymorphism follow the same basic concept - manipulating different objects in code through a common interface without needing specific data type information about those objects
FrozenSnake, on 20 October 2012 - 11:39 PM, said:Do you mean Encapsulation? Note that 'implementation hiding' applies equally to the behaviour of an object (i.e. the details which describe how it works); data hiding is only one part of this.Capsulation: capsulation can happen on different levels and be used to hide data. Depending on level we can do different things with functions and variables.
For example, a badly-encapsulated class called DeckOfCards might include member functions called GetNumberOfCards() and SetNumberOfCards(). Both of these are probably bad because they "leak" the internal behaviour of the object, expecting the user of the class to do the leg-work. a class modelling a deck of cards is more likely to want member functions such as DrawCardFromTop, ReplaceCardToBottom, ShuffleDeck, IsDeckEmpty etc.
FrozenSnake, on 20 October 2012 - 11:39 PM, said:The act of inheriting a class could also be described as defining a new class whose interface and implementation are an extension of an existing class. Another word would be Specialisation.Inheritance: Inheritance makes it possible for subclasses to inherit functions and variables from one or more classes. The subclasses will inherit both functions and variables. -
In Topic: abstract base class and shared_ptr
Posted 29 Sep 2012
The semantics of shared_ptr are deliberately designed to mirror raw pointers as closely as possible; similarly, the semantics of make_shared are deliberately designed to mirror the new operator as closely as possible. The idea being that you should be able to use them as direct drop-in-replacements for legacy code with minimal change to the code. (Think of them as abstractions of pointers and new in the same way that iterators are designed as abstract pointers)
So, a shared_ptr<Derived> has semantically the same relationship to shared_ptr<Base> as you would expect between 'raw' pointers Derived* and Base*.
In the dark days before shared_ptr, you'd be forced to do code like this:Base* b = new Derived;
With shared_ptr, you would typically expect to see the replacement code look like:std::shared_ptr<Base> b = std::shared_ptr<Derived>(new Derived);
make_shared is not actually required - so it's "OK" to pass a parameter using 'new' if you wish, but the code looks clunky. make_shared helps everything look cleaner. (Notably, it reduces repetition of the name Derived)
std::shared_ptr<Base> b = std::make_shared<Derived>();
or, of course, even cleaner:auto b = std::make_shared<Derived>();
Where make_shared<Derived() is an abstraction of new Derived();, the same is true for make_shared<T>( arg1, arg2) - it is semantically equivalent to new T( arg1, arg2 );.
The implementation of make_shared is achieved using variadic template arguments which are forwarded to new. -
In Topic: errors as to array in sort and something about ( ) in sort?
Posted 23 Sep 2012
It would help if you could post a description of the problem you are having, including any compiler errors or other information.
After a quick look at your code, there's one obvious problem here:
JMurray308, on 23 September 2012 - 06:42 PM, said:Here you are calling your sortArray function before you have even initialised scores or allocated any memory for itint main() { int numScores; //declare variables double average, *scores; double totalScores = 0.0; //initialize totalScores cout << "Enter the size of the numScores array: "; cin >> numScores; sortArray(scores, numScores); scores = new double[numScores]; // set dynamic memory allocation -
In Topic: What does "public: " mean?
Posted 22 Sep 2012
You might also want to take a more general look at Object-Oriented programming, since the concepts are all tightly inter-related; including the struct, class private and protected keywords.
OOP is a huge topic, and one place you can go to learn is Google.
- wikibooks link on OO in C++ http://msdn.microsof...y/kktasw36.aspx
- MSDN link on class member access - http://msdn.microsof...y/kktasw36.aspx
- Google search: https://www.google.c...ramming+C%2B%2B -
In Topic: Replacing strings in arrays w/o using string string.h class
Posted 22 Sep 2012
xcrusader, on 22 September 2012 - 07:21 PM, said:char mystrcpy() without the * is a function returning a charCan I also know what the difference between char mystrcpy() and char *mystrcpy() is? I get that both functions should be returning a char, but whats the * saying about the funtion?
In this context, the asterisk * is known as the pointer declarator, meaning the return type of char* mystrcpy() is char* (read right-to-left, it means pointer-to-char).
When you declare any kind of variable using an asterisk the C++ type system provides you with a pointer-type variable (i.e. a numeric variable whose data represents a memory address). Any data type which has a * next to it is typically pronounced as pointer-to-(something..)
In short, the * does not belong to the function at all, it belongs to the data type.
Some links on the subject of pointers and arrays which are very well worth your time reading:
http://www.eternally...t_pointers.aspx
http://www.daweidesi...in/pointers.php
http://www.augustcou...torial/ptr.html
http://www.augustcou...torial/arr.html
http://www.c-faq.com/ptrs/index.html
http://www.c-faq.com/aryptr/
http://www.codeproje...-C-declarations
My Information
- Member Title:
- D.I.C Lover
- Age:
- 30 years old
- Birthday:
- August 15, 1982
- Gender:
-
- Location:
- UK
- Years Programming:
- 8
- Programming Languages:
- C, C++
Contact Information
- E-mail:
- Private
- Website URL:
-
http://
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
Sy-Coderz
23 Jun 2012 - 09:47bro please add me at : x1d@hotmail.com
add me please i need some help
i wait u
OLH064
28 Aug 2011 - 11:09Jeff H
19 Jun 2011 - 00:54I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
Just let me know what I need to do to help get it changed. I already left a reply in the thread.
Jeff H
19 Jun 2011 - 00:54I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
Just let me know what I need to do to help get it changed. I already left a reply in the thread.
sleepybug
20 Feb 2010 - 06:45neptunusmaris
16 Feb 2010 - 10:56CodingDesire
16 Feb 2010 - 09:21