Beginner MS Visual C++ User

This is a discussion on Beginner MS Visual C++ User within the C++ Programming forums, part of the General Programming Boards category; I have just downloaded Visual C++ and am trying to write a noddy application. I am well versed in C++ ...

  1. #1
    Registered User SpaceCadet's Avatar
    Join Date
    Oct 2006
    Posts
    23

    Question Beginner MS Visual C++ User

    I have just downloaded Visual C++ and am trying to write a noddy application. I am well versed in C++ and write for the unix platform.

    I am therefore bemused by the compilation errors MS VC++ gives!


    Here are the headers///

    Code:
    #pragma once
    
    ref class FactoryBase
    {
    public:
    	FactoryBase(void);
    public:
    	virtual ~FactoryBase(void);
    };
    
    
    #pragma once
    #include "factorybase.h"
    class Widget;
    
    ref class Factory : public FactoryBase
    {
    public:
    	Factory(void);
    public:
    	virtual ~Factory(void);
    
    	Widget * const CreateWidget();
    };
    
    
    #pragma once
    
    ref class Widget
    {
    public:
    	Widget(void);
    public:
    	virtual ~Widget(void);
    };
    And now for the source!

    Code:
    // Factory.cpp : main project file.
    
    #include "stdafx.h"
    #include "Factory.h"
    #include "Widget.h"
    
    using namespace System;
    
    int main(array<System::String ^> ^args)
    {
        Console::WriteLine(L"Hello World");
        return 0;
    }
    
    Factory::Factory(void)
    {
    }
    
    Factory::~Factory(void)
    {
    }
    
    Widget * const Factory::CreateWidget()
    {
    	return new Widget();
    }
    #include "StdAfx.h"
    #include "FactoryBase.h"
    
    FactoryBase::FactoryBase(void)
    {
    }
    
    FactoryBase::~FactoryBase(void)
    {
    }
    
    
    #include "StdAfx.h"
    #include "Widget.h"
    
    Widget::Widget(void)
    {
    }
    
    Widget::~Widget(void)
    {
    }


    Finally this output?

    Code:
    1>------ Build started: Project: Factory, Configuration: Debug Win32 ------
    1>Compiling...
    1>Factory.cpp
    1>c:\documents and settings\kevin matthews\my documents\visual studio 2005\projects\factory\factory\Widget.h(4) : error C3816: 'class Widget' was previously declared or defined with a different managed modifier
    1>        c:\documents and settings\kevin matthews\my documents\visual studio 2005\projects\factory\factory\Factory.h(3) : see declaration of 'Widget'
    1>.\Factory.cpp(24) : error C3699: '*const ' : cannot use this indirection on type 'Widget'
    1>        compiler replacing '*const ' with '^' to continue parsing
    1>.\Factory.cpp(24) : error C2556: 'Widget ^Factory::CreateWidget(void)' : overloaded function differs only by return type from 'Widget *const Factory::CreateWidget(void)'
    1>        c:\documents and settings\kevin matthews\my documents\visual studio 2005\projects\factory\factory\Factory.h(12) : see declaration of 'Factory::CreateWidget'
    1>.\Factory.cpp(24) : error C2373: 'Factory::CreateWidget' : redefinition; different type modifiers
    1>        c:\documents and settings\kevin matthews\my documents\visual studio 2005\projects\factory\factory\Factory.h(12) : see declaration of 'Factory::CreateWidget'
    1>.\Factory.cpp(25) : error C2750: 'Widget' : cannot use 'new' on the reference type; use 'gcnew' instead
    1>Build log was saved at "file://c:\Documents and Settings\Kevin Matthews\My Documents\Visual Studio 2005\Projects\Factory\Factory\Debug\BuildLog.htm"
    1>Factory - 5 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Is this Managed C++ or C++/CLI or something? The error messages indicate that you aren't compiling as regular C++. If you meant to use standard C++ as you would on unix, then you have to create a Win32 Console Application project to get the right settings. If you meant to use the .NET based languages, then you might get more help in another board as most of the people here, even those who use Visual C++, are using regular C++.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    It definitely is trying to compile it as C++/CLI, not C++.

    Though it seems like you're not writing pure C++ either with a line like:
    int main(array<System::String ^> ^args)
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I think it's trying to compile as C++, but the code looks to me like .NET
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Registered User SpaceCadet's Avatar
    Join Date
    Oct 2006
    Posts
    23
    I will check whether I messed up at first base! (Specifying a C++ console application)

    Thanks all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Forms and MS Visual C++ .NET
    By xddxogm3 in forum C++ Programming
    Replies: 1
    Last Post: 05-24-2007, 06:50 PM
  3. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 10:45 AM
  4. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 04:22 AM
  5. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 01:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21