Why public ref in c++ class definition

21,639

Solution 1

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.

Solution 2

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....

Solution 3

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).

Solution 4

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

Share:
21,639
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.