Solved

A Few Newbie C++, Visual Studio Questions

Posted on 2004-09-14
5
187 Views
Last Modified: 2010-04-24
Hi, thanks in advance for your help. I am new to C++ and have just started using Visual C++ .NET and these are my first initial questions. I appreciate any help you can give on any or all. Thanks again.

1. When I build and there's an error, how can I make sure it tells me details about the errors so I can know what to troubleshoot?
2. I don't fully understand when to use void and when to use int for the main function and in general.
3. Significance of passing by value as opposed to by reference.
 
0
Comment
Question by:frogpad
  • 3
5 Comments
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 250 total points
ID: 12061530
I'm not quiet sure I got your first question right, so - on the second.You should return int from main if your application is invoked by another app (or batch file or somethig) and the calling app needs to know what happend during the execution - so you can return some error code (or success) from main().
On your 3d question - when you're passing parameter by value your parameter can be modified only inside the method you're calling - and you're not actually modifying the parameter itself, but a copy.When you're passing value by reference you can modify it and no copy is created.
So you can run this simple program and watch the results - when calling by reference or by value:

#include "stdafx.h"
#include <conio.h>

void ByVal(int someInt)
{
      someInt = 5;
}

void ByRef(int* someInt)
{
      *someInt = 10;
}

int _tmain(int argc, _TCHAR* argv[])
{
      int test = 1;
      printf("Initial value of test: %d\n",test);
      ByVal(test);
      printf("Value of test after calling ByVal: %d\n",test);
      ByRef(&test);
      printf("Value of test after calling ByRef: %d\n",test);
      getch();
}
0
 
LVL 16

Assisted Solution

by:nonubik
nonubik earned 250 total points
ID: 12062628
1. The errors are usually displayed in the 'Output' and 'Task list' windows. You can also have a build log : menu Tools->Options->Projects->VC++ Build->Build Logging select yes.

2.Whether you want or not to return an exit code to the parent process or operating system using a return statement. Although to return an exit code when main or wmain is declared as void, you must use the exit function. Better see http://msdn.microsoft.com/library/en-us/dv_vccelng4/html/ellrfmaincolprogramstartup.asp

3. Svetlin_Panayotov has quite answered to this, I'll just add:

void ByRef(int  &someInt)
{
     someInt = 10;
}

another form of passing by reference
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12063083
About 1.
If that's your question - nonubik explained it well.Just to add this - if you select an error(or warning) from "Task list" and press F1 - you'll get a detailed explanation, possible reason and maybe a sample - if the guys at MS that write their help were in good mood :)
0
 

Author Comment

by:frogpad
ID: 12076834
great, thanks very much guys, your feedback is much more clear than the text I am reading. Kudos.
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12078335
You're welcome :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how do i save an image to a table using c# 10 99
Microsoft Visual C++ Runtime Lirary Runtime Error 15 374
C# - Function parentheses 11 59
c++ open source accounting software 3 120
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question