Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:07:29+00:00 2026-05-23T17:07:29+00:00

I am having problems creating a managed class with namespace in C++/CLI. I would

  • 0

I am having problems creating a managed class with namespace in C++/CLI.

I would like to do the following:

#pragma once
#include "abc.h"
#ifdef _MANAGED
#using <system.dll>
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
using namespace System::Globalization;
#endif

namespace Animals
    {
    public ref class Pets
        {
        Pets::Pets(){}
        };
    }

I have a couple different problems:

A) When I place this code into the .cpp file, it compiles fine. However, it appears the namespaces are not working as expected (see this question I created: Namespace not recognized in C++/CLI) The only answer listed says I must declare the classes/namespaces in the header file. But this is a problem because..

B) The compiler complains about public ref class Pets when it is placed in the header file. It says there must be a syntax error.

intellisense error:

expected a declaration

other errors:

'{' : missing function header (old-style formal list?)

syntax error: 'public'

I can’t seem to find any great C++/CLI examples that show both the header and the cpp file.

So my question is: How can I make both the managed class and namespace work as expected? (i.e. what am I doing wrong?)

Please let me know if I need to include any more information.

Thanks in advance for your time and patience 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:07:29+00:00Added an answer on May 23, 2026 at 5:07 pm

    In the header file there should just be forward declarations.

    // abc.h
    #pragma once
    
    namespace Animals
    {
        public ref class Pets
        {
            Pets(); // forward declaration
            // Pets::Pets is redundant and wrong, because you are inside 
            // the class Pets
        };
    }
    
    
    // abc.cpp
    #include "abc.h"
    #ifdef _MANAGED
    #using <system.dll>
    using namespace System;
    using namespace System::IO;
    using namespace System::Collections::Generic;
    using namespace System::Globalization;
    #endif
    
    namespace Animals
    {
        Pets::Pets() {}  // implementation
        // Now Pets::Pets() is right, because you dont write the class... wrapper again.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems creating WCF client proxy for service code like in this
I have been having problems with creating a download list of files for a
I'm creating a website for my church and I'm having problems making it display
We're having a significant number of problems creating a bulk upload function for our
I'm having problems creating a collection of delegate using reflection and generics. I'm trying
I have been having problems creating a relative layout in XML for a list
I am having some problems creating a query that gives me the average of
I'm having some problems creating a view for a node within my website. The
I seem to be having some problems creating a jquery plugin. I am testing
Having a few problems with Timers within a service on Win2k3... Basically, creating a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.