Tuesday, June 8, 2010

OOAD Tips

  • Never inherit from a concrete class!

Monday, March 9, 2009

Stack Implementation in C++

Check the following link for the implementation of a stack in C, C++ and Java.
http://www.cs.utsa.edu/~wagner/CS2213/stack/stack.html

Friday, January 23, 2009

Working with Strings

When mixing strings and string literals, at least one operand to each + operator must be of string type:

     string s1 = "hello";   // no punctuation
string s2 = "world";
string s3 = s1 + ", "; // ok: adding a string and a literal
string s4 = "hello" + ", "; // error: no string operand
string s5 = s1 + ", " + "world"; // ok: each + has string operand
string s6 = "hello" + ", " + s2; // error: can't add string literals

Wednesday, January 21, 2009

Error C2065: 'endl' : undeclared identifier

  • To avoid this error we should use the following statement:

using namespace std;

Monday, November 17, 2008

Error C2628::Missing semicolon at the end of the class.

  • The error is perhaps the most common errors to encounter among C++ newbies.
class Foo {
// empty
} // Note: no semicolon
int main()
{
return 0;
}

  • Remember to include a semi colon after each class to avoid the error.

Friday, October 17, 2008

Parking Lot

  • A comment that begins with /* always ends with the next */. As a result, one comment pair cannot occur within another.
  • Headers for the standard library are enclosed in angle brackets (< >). Nonstandard headers are enclosed in double quotes (" "). eg: #include<> #include"SaleItem.h".

  • We can declare a name without defining it by using the extern keyword. A declaration that is not also a definition consists of the object's name and its type preceded by the keyword extern:

          extern int i;   // declares but does not define i
    int i; // declares and defines i
  • extern double pi = 3.1416; // definition
  • constvariables are local to a file by default. To make a const variable accessible to other files we must explicitly specify that it is extern.
  • By default, the access level in C++ in classes is Private.
  • Header files are for Declarations, Not Definitions.
  • It might be logical to expect that size returns an int or an unsigned. Instead, the size operation returns a value of type string::size_type.

Thursday, October 16, 2008

How to build and execute any dumb C++ program on VS2008

One of the most common initial errors which the newbies to Visual Studio encounter
ERROR::::: general error c1010070: Failed to load and parse the manifest.

Follow the steps below to workaround your first roadblock in compiling C++ programs in Visual Studio 2005/2008.

1. Click File>New>Project
2. Select Other Languages>Visual C++ > Win32 in the left pane. Select Win32 Console Application in the right pane.
3. Name the project and click Ok.
4. In the next Pop-up, Click on Application Settings.
5. Click Project>Add Existing Item.
6. Select a checkbox for "Empty Project".
7. Click Finish.
8. In the Solution Explorer, under Source files, Right click and select Add Item.
6. Select a .cpp file
7. Name the file and press Ok/finish.
8. Add your code.
9. Build your Solution(F6)
10. Execute it (F5)

You should be good to go with that.

Tip>> Always avoid having names of projects or cpp files as Example1.1 and so on as VS 2005/2008 do not tend to like the "." in between the names.