Simple tutorial for C++

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
I have tried your method,but it ask me to port over my code;

ftk8yr.png


you mean there are so many variants of C++?
C++11,MFC,STL,C,Objective C,that is why when i type in google there are so many solution,but which one could be the right one.

C++11 is the most recent version/revision of the ANSI ISO C++. This is the standard C++ that most people refer to and is platform and compiler neutral i.e. it looks and works the same on Windows, Linux and Unix, and is compilable by any standard C++ compiler.

Objective-C is influenced by C but with object-oriented characteristics added in. It was developed along the same period as C++ concurrently but Objective-C and C++ ended up as two different derivative languages with a common ancestor C. Objective-C is only used by Apple and MacOS afaik.

MFC and STL are C++ libraries of commonly used functions used in C++ programming. They are not the language itself.
 

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,470
Reaction score
1,534
MFC and STL are C++ libraries of commonly used functions used in C++ programming. They are not the language itself.

Why are MFC & STL being compared?
MFC is compared with other user interface library.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Dear twinbaby,

I highly recommend that you go pick up the C programming books follow by the C++ programming books, then the STL follow by MFC. C++11 is better left alone until you get the basic of C++ right.

While it seems some C++ books do not assume newbies to have C knowledge, my recommendation is learn C first. C++ foundation are based on C. The Object Oriented portion of C++ are new to C. STL is the natural companion of C++ because the template nature of STL allows for generics to function. Without STL, C++ would have a hard time building the hierarchical inheritance model since in C++ there is no root class so to speak. With STL, generic containers are possible with strict typing, if not, you will be using a lot of "void type pointers", and "void type pointers" are not strict typing in nature. C++ compiler will not be able to perform type checking at static code analysis using compilation.

MFC is Microsoft Foundation Class. It is not comparable to STL. I believe there are a lot of 3rd party libraries out there built based on the foundation of STL, not MFC. MFC main objective is to provide much of Win32 API which previously are only exposed via the C interfaces. Containers in MFC are provided to facilitate the inner workings of MFC, but NOT as the generic containers and algorithms utility for C++.

Back to my earlier point, you are nitpicking on the knowledge and not learning the foundation of C/C++. This is going to just introduce more knowledge gaps and missing fundamentals for you to truly understand C/C++, less alone STL and MFC.

Learning C, C++, STL will not limit you to any platform. These are general knowledge no matter which platform you are on that support C and C++. MFC is only found in the Microsoft platform.

Please follow the right path to gain your knowledge, don't be confused among these terminologies. You are now like a headless housefly banging around.

Just to give you a nice comparison between Java and C++ and using STL

In Java
Code:
// without generics
List mylist = new ArrayList();
mylist.add(new Integer(11));
Integer i = (Integer)mylist.get(0);

//with generics
List<Integer> mylist = new ArrayList<Integer>();
mylist.add(new Integer(11));
Integer i = mylist.get(0);

In C++
Code:
list<int> *mylist = new list<int>();
mylist->push_front(11);
int i = mylist->front();

In Java, you have the root Object class and interface, because of this well defined hierarchy, even in Java, you can have generic container that operate using Object as the items in the container before generics. The runtime reflection of Java helps a lot to allow real implementation methods to be invoked inside the container even if the actual type of the object is unknown. Such as if my list contains ["Hello", Integer(1), Float(1.3)], calling toString method of Java will print out "Hello", 1 and 1.3 respectively.

In C++, this is not possible because the inheritance model of C++ is not as well defined as Java. Without STL, your generic container will be (void*), it means a memory address pointer that point to somewhere at address XYZ. Nothing is known about the object placed there, you can't even query if it's an integer there or an object.

With STL, it will be similar to the later established Generics of Java. Even that, Generics in Java are a lot more powerful because of type inference and type checking, but Generics makes programming in Java more complicated especially where Generics are not covariant.

In C++, you have to explicitly specify the types of a container. It is unlike Java limited to objects only. As a template engine, it allows for any types as long as the type rules comply. C++ template engine is very powerful too. I have come across that it can be used solely to implement type inference to the extent beyond my comprehension.

I hope these shed some lights into how complicated things can be, so please build up your foundation, don't waste time hitting around aimlessly.
 
Last edited:

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
Why are MFC & STL being compared?
MFC is compared with other user interface library.

I only highlighted MFC as an example how Microsoft likes to introduce its own proprietary technology and extensions. By using things like MFC library in your C++ project -- which is unavailable to other C++ compilers -- you are restricted to using Microsoft Visual C++/Visual Studio to build your C++ project which runs only on Windows.

If you're conscientious enough to avoid these proprietary stuffs and use only pure ANSI/ISO C++, you can copy the same set of .cpp files to Unix/Linux and recompile using GCC, and it will still work with zero or minimal changes. Of course, I'm making some major oversimplifications here.

STL is available for all major C++ compilers and platforms, so I prefer it, just in case one fine day, I have to rebuild my code base for Unix/Linux using GCC. If you've a major C++ project written over many years and accumulated thousands of lines of codes, it's not funny or trivial trying to port it over.

The one place that MFC and STL overlaps is in the provision of standard data structures like linked lists, stacks and maps. However, MFC is a kitchen sink that also handles Windows GUI programming, which STL does not cover. I hope this brings a little more clarity.

Anyway just to add, at your current stage, you can safely ignore STL and MFC for the time being. They are irrelevant to you at the moment, and are not even essential or necessary for you know in order to write a C/C++ program. Focus on understanding the normal pure ANSI/ISO C and C++ first.

Just a personal note, I was quite fortunate my lecturers taught me C/C++ programming in Linux/Unix (SunOS) environment with GCC where I learnt the ISO/ANSI C/C++, instead of being distracted and confused by the all the extra fanciful proprietary stuffs offered by Microsoft Visual C++ or Borland C++ Builder. As an analogy, I learned to bake the simplest (but also most boring) white bread before attempting to bake other flavoured breads or other pastries. There's no shortcut in learning the basics.
 
Last edited:

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,470
Reaction score
1,534
Ok,to take on any programming assignment,we need to know at the how to do this.Anything missing please advice.

  1. Write a Hello World
  2. Create a Loop
  3. Write an Conditional Statement
  4. Display item(s) in an array
  5. Read a .txt file

I believe writing if-else & switch statement are essential as well.
 

ryanlimes

Junior Member
Joined
Jul 26, 2014
Messages
8
Reaction score
0
I believe writing if-else & switch statement are essential as well.

dont bother so much about checking the check list.... as long as you understand what the language is about, you will automatically be able to do all of them.

pick up a damn c/c++ book and read. i seen a lot of classmate who struggled with programming and the reason? none of them bothered with the fundamentals (but usually that also means you are not suitable for programming).
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
dont bother so much about checking the check list.... as long as you understand what the language is about, you will automatically be able to do all of them.

pick up a damn c/c++ book and read. i seen a lot of classmate who struggled with programming and the reason? none of them bothered with the fundamentals (but usually that also means you are not suitable for programming).

A programmer is a person actively developing a solution for a problem, not a customer waiting to be served with a ready-made solution. That's the reason why they're paid for their effort (i.e. intellectual work).

It's really a person's attitude and aptitude that determines one should aspire to be a programmer or not. For people who are passive about learning and lethargic about thinking, then programming is something that gets on their nerves and thus best avoided.

I have heard of fresh IT grads who aspire to be project managers straight out of school. Reason? Maybe they only want to be spoonfed by vendors with ready made solutions instead of worrying over the technical nitty-gritties. They just dump project requirements on vendors who would then return to propose their solutions.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Try vi/vim or emacs. It's the best tool for real programming.

Trying too hard lah :) there are still good use for IDE, there is no such thing as real programming, only good or bad :)

I have been a VIM user for more than a decade, but still I find IDE good for really large scale development :)

Don't be biased against tools, know where they are good at and what they are good for :)
 

ryanlimes

Junior Member
Joined
Jul 26, 2014
Messages
8
Reaction score
0
Anyway, for learning it's better to use an IDE like codeblocks, since you will want to see it compile and run.

you can always compile with cygwin... the prob with using IDE to learn is that ppl tend to rely too much on intellisense and the debugger to solve their bugs.

another prob with learning with IDE is that they usually you end up thinking that the only way to run their program is thru IDE....
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top