Welcome! Log In Create A New Profile

Advanced

Visual Studio vs DevC++

Posted by AndreB 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Visual Studio vs DevC++
April 12, 2007 08:55AM
I forced myself to stick to using DevC++ for the 1st year programming modules - however I've recently decided to rather work in Visual Studio. I have picked up 1 or 2 issues here and there, but it is generally a much friendlier environment to work in.
I'm not sure why Unisa does not supplier (at an extra cost) Visual Studio C++ - Students version instead of a free/shareware product like DevC++. I do understand the hassles of increasing the cost of a module, however any commercial programming in C++/VisualC++ will be done mostly in Visual Studio (maybe a few companies still using Borlands). It would just make more sense to get students used to learning/working in the environment most widely used (only my opinion of course).

Is there anyone else out there using Visual Studio instead of DevC++?

AndreB
Re: Visual Studio vs DevC++
April 12, 2007 08:58AM
Having said the above, I'm having linker hassles referencing my Chapter 3 ArrayListType template class with my main function.
I can get ArrayList and main to compile seperatley, however when building the solution I get a whole bunch of LNK2019 errors:

ADT_ArrayListType error LNK2019: unresolved external symbol "public: __thiscall cArrayListType<class cNewString>::~cArrayListType<class cNewString>(void)" (??1?$cArrayListType@VcNewString@@@@QAE@XZ) referenced in function _main

Any ideas?
avatar Re: Visual Studio vs DevC++
April 12, 2007 11:19AM
Firstly AndréB, Microsoft has released a string of Express editions for students that are free to download (about 91MB minimum). They've split the whole of Visual Studio into it's separate parts (VB, C/C++, C#, J#, Web Developer, etc.) so there's an Express edition for each instead of one program for all.

Secondly, I use Visual Studio 2003 at home and love it. The error messages are so much more descriptive than those of MinGW. Case in point, your error says that there is no destructor defined. Check your code again.

The fact that your code files are compiling separately just means that your code is correctly formed (ie no syntax errors). This error is a linking error meaning it occurs when you try to splice your source files together.

If you don't specify a destructor in your class definition then one is created by default. Since there is a linker error, it means that you've declared that you'll create one but have forgotten to do so. Look in your header file for a function
cArrayListType<class cNewString>::~cArrayListType()
  {
  // some code here
  }
If you don't see this in your header file, then you need to create it or else remove the declaration from your class definition.
avatar Re: Visual Studio vs DevC++
April 12, 2007 11:53AM
Just thought of something else. Your class is a template class and this sometimes causes confusion.

Template classes are not classes in themselves like the other classes you create. They are just instructions to the compiler on how to make the real classes. Every time you instantiate a template class with a different type, the compiler creates the real class. This may sound a bit abstract so I'll give an example.

Suppose you create the following:
template<class UserType>
class Printer
  {
  public:
    Printer(UserType const &initialValue);

    void Print();

  private:
    UserType m_value;
  };

template<class UserType>
Printer<UserType>:: Printer(UserType const &initialValue)
  : m_value(initialValue)
  {}

template<class UserType>
void Printer<UserType>:: Print()
  {
  cout << "The value is: " << m_value << endl;
  }

This is just a template of a class, not a real class. If I were to create two versions of this class in the main() function:
void main()
  {
  Printer<int> integerPrinter;
  Printer<float> floatPrinter;
  // some other code
  }
Behind the scenes the compiler will create the real classes for these two instances.
class Printer<int>
  {
  public:
    Printer(int const &initialValue);

    void Print();

  private:
    int m_value;
  };

Printer<int>:: Printer(int const &initialValue)
  : m_value(initialValue)
  {}

void Printer<int>:: Print()
  {
  cout << "The value is: " << m_value << endl;
  }

class Printer<float>
  {
  public:
    Printer(float const &initialValue);

    void Print();

  private:
    float m_value;
  };

Printer<float>:: Printer(float const &initialValue)
  : m_value(initialValue)
  {}

void Printer<float>:: Print()
  {
  cout << "The value is: " << m_value << endl;
  }

This is just an illustration of how the real classes might be created by the compiler. How they are actually created is irrelevant, the fact is that the compiler creates a new class based on the template for each instance that has a new type. If you create four Printer<int> objects and two Printer<float> objects there will only be two new classes created. If you decide to modify your program to also have five Printer<string> objects then the compiler will create the Printer<string> class based on the template (substituting UserType with string)

The reason I'm raising this issue is that ordinary programming convention says that you have to place the class definition (the interface) in a header file and the member function definitions (the implementation) in a separate source file. You cannot do this with template classes.

Because the compiler needs to know everything about a template class (the interface and the implementation) in order to create new classes based on those templates, you have to include the entirety of your class in every source file that uses it. Thus both the interface and the implementation of template classes must be in an included header file.

Thus, AndréB, if you have indeed created a destructor, make sure the definition is in the included header file and not in a source file.
Re: Visual Studio vs DevC++
April 12, 2007 12:25PM
Brilliant Robanaurochs,

It was indeed the fact that I had split the definition and implementation of the template class (btw I had explicitly provided the definition and implementation of the destructor).
Silly me I had placed the implementation in a source file.

Great - Thanks.
AndreB
Re: Visual Studio vs DevC++
April 12, 2007 12:26PM
Hi Rob....

As to your first feedback - why then not make Visual Studio the default environment for the programming modules. It is the most likely environment to be used in practice.

Cheers,
avatar Re: Visual Studio vs DevC++
April 12, 2007 12:33PM
As I said earlier, Visual Studio is the combined IDE for a number of languages. The free student version for c/c++ is Visual C++ Express Edition. You can download that one for free from the microsoft website.

As for making it the default, I would hope so. But it won't work for COS311 since Qt4 requires some extra jiggery-pokery in order to compile properly so you can't even use DevC++. I'm still working out how to port Qt to VS but I haven't spent much time on it.
Sorry, only registered users may post in this forum.

Click here to login