Solved

A Few Newbie C++, Visual Studio Questions

Posted on 2004-09-14
5
156 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now