views:

1431

answers:

4

Hi,

First of all I want to make clear that 'm all new to C++, so this might be a simple and somewhat obvious question. In the C++ book I'm reading called C++ Primer, a class is defined by writing:

class classname{
public:

private:

};

However, in VS2008 the compiler didnt like this. But by adding public ref before class, as in:

public ref class classname{

it went through in the compiler. Can anyone please explain what the difference is between defining only with class and with public ref class? I would really appreciate it.

+11  A: 

The ref syntax is a Microsoft extension used only in Managed C++. By the sounds of things you have flicked the /clr compiler switch on by mistake when creating your project. If all you want to do is to create real C++ programs, then you will want to revert that.

1800 INFORMATION
yes, the "public ref" bit is not standard C++
Steg
+3  A: 

You're reading a book call C++ Primer which teaches the C++ programming language, whereas you're attempting to create a program telling VC++ the code is in C++/CLI, a different programming language....

KTC
+1 Programming in the same language that you learnt usually helps.
Daniel Daranas
+1  A: 

Are you learning the standard C/C++ language? if the answer is yes then that syntax is concerning the Microsoft C++/CLI language...

look at : C++/CLI

Try to use Eclipse with C++ extension instead. It cames with all you need to create and execute a STANDARD C++ program!

Eclipse download

xdevel2000
He's reading a C++ book, so I would presume he's learning C++.Why the advert for Eclipse? VC++ is a perfecting good IDE / compiler to create a C++ program on Windows. You just need to make sure you select the right project types. A problem that still exist with something like Eclipse if someone decide to select say a Java project and then trys to write a C++ program.
KTC
@KTC: Because VC++ actively diverts you from ISO C++ path. "Secure" CRT, anyone?
EFraim
+2  A: 

You (edit: and other users) tagged this question with:

  • Two programming languages: C++ and C++/CLI,
  • One commercial Integrated Development Environment (IDE) by Microsoft: Visual C++, which lets you program in three different languages (C, C++ and C++/CLI). In the post you mention Microsoft Visual Studio 2008, which is a superset of Visual C++.
  • One set of language extensions: Managed C++, which has historically refered to quite a few different things and, frankly, I'm not sure what it means now :)

However, your first goal should be to learn how to configure Visual C++ to program in the language of your choice, C++.

As usual, a good way to find an answer to this question is to type it in the "Ask Question" page and see which related questions are suggested. This is the best one, I think: compiling "standard" C++ in visual studio (non .net).

Daniel Daranas
* AProgrammer retagged the question adding C++/CLI after reading the question. The OP didn't know about it.
KTC
Oops, thank you KTC.
Daniel Daranas