473,472 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Namespaces in VC++.NET and C#

Hi All,

I created a .NET class library in C# (VS 2005 Beta 2) sometime back. I used
to group my interfaces and classes in namespaces like-

abc.cs
--------
namespace CompName.DomName.TechName.ProductName.Namespace1
{
public class/interface xyz
{
method1();
method2();
}
}
where there is no namespace like only CompName or DomName or TechName or
ProdName or combination of these. Actual namespace containing
interfaces/classes is only Namespace1 or Namespace2.
The above strategy compiled and worked fine.
Now, my client has said to convert the code to VC++ .NET (VS 2005 Beta2).

Now I am declaring the same C# code in C++ like-

abc.cpp
----------
#include "StdAfx.h"
#include "abc.h"

abc.h
-------
using namespace System;
namespase CompName::DomName::TechName::ProductName::Namespac e1
{
public class/interface xyz
{
method1();
method2();
}
}
This gives compiler error "Namespace1 is not a valid class/namespac".

Can anybody help me? How to do it in VC++.NET.

Regards,
RS
Sep 8 '05 #1
3 1541
"Ratan" <Ra***@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
using namespace System;
namespase CompName::DomName::TechName::ProductName::Namespac e1
{
public class/interface xyz
{
method1();
method2();
}
}
This gives compiler error "Namespace1 is not a valid class/namespac".


Oh the joy. It's so long since I've done any managed C++ I'd forgotten about
this little gem. Assuming this hasn't been fixed, and from your post it
looks like it hasn't, here's how you do it. Actually, here's how you do it
in C++ generally, not just MC++.

namespace A
{
namespace B
{
namespace C
{
//Class Def
}
}
}

This will define a class in the namespace A::B::C. Joyous isn't it :)

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Sep 8 '05 #2
Hi!
Now I am declaring the same C# code in C++ like-

abc.cpp
----------
#include "StdAfx.h"
#include "abc.h"

abc.h
-------
using namespace System;
namespase CompName::DomName::TechName::ProductName::Namespac e1
{
public class/interface xyz
{
method1();
method2();
}
}
This gives compiler error "Namespace1 is not a valid class/namespac".


Try this:

namespace CompName
{
namespace DomName
{
namespace TechName
{
namespace ProductName
{
namespace Namespace1
{
public class/interface xyz
{
method1();
method2();
}
}
}
}
}
}

A bit nasty, isn't it? But according to C++ grammar in VC++ help there's
no other way... Or maybe I'm wrong.

Cheers,
Piotrek

Sep 8 '05 #3
Hi,

Thanks to both of you Tim Haughton and Piotr Szukalski.
I was doing that way but wanted to confirm if that is a good way. Now since
both of you suggested the same technique, it is clear that this is the only
way.

It is very lengthy so Microsoft should support declaring namespaces in the
same way as it is with C#.

Regards,
RS

"Piotr Szukalski" wrote:
Hi!
Now I am declaring the same C# code in C++ like-

abc.cpp
----------
#include "StdAfx.h"
#include "abc.h"

abc.h
-------
using namespace System;
namespase CompName::DomName::TechName::ProductName::Namespac e1
{
public class/interface xyz
{
method1();
method2();
}
}
This gives compiler error "Namespace1 is not a valid class/namespac".


Try this:

namespace CompName
{
namespace DomName
{
namespace TechName
{
namespace ProductName
{
namespace Namespace1
{
public class/interface xyz
{
method1();
method2();
}
}
}
}
}
}

A bit nasty, isn't it? But according to C++ grammar in VC++ help there's
no other way... Or maybe I'm wrong.

Cheers,
Piotrek

Sep 8 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
12
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
12
by: RA Scheltema | last post by:
Hi all, I have the following code: namespace A { inline void func(int) { ...; } inline void func(float) { ...; } inline void func(char) { ...; } }
4
by: Sean Quinn | last post by:
Recently I've come across an oddity in .NET, going back to a Managed C++ implementation for GUIs since I never really learned how to code in MFC. Any way, I attempted to put some standard code I...
9
by: Patty O'Dors | last post by:
Hi Can somebody please tell me what namespaces are actually for? I notice that when I start a new project in C#, it puts everything in a namespace of the same name as the project. I found them...
2
by: Chris Bearchell | last post by:
I am trying to get browse information for a VS.net 2003 C++ project, however I am running into trouble resolving methods within a namespace. From within the object browser, all methods within a...
0
by: kashiDeveloper | last post by:
-------------------------------------------------------------------------------- Hi! Plz anybody can give me idea about using Different My-own-created Namespaces in a single VC++.NET...
3
by: Ratan | last post by:
Hi All, I created a .NET class library in C# (VS 2005 Beta 2) sometime back. I used to group my interfaces and classes in namespaces like- abc.cs -------- namespace...
11
by: jakester | last post by:
I am using Visual C++ 2007 to build the code below. I keep getting linkage error. Could someone please tell me what I am doing wrong? The code works until I start using namespace for my objects. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.