using a namespace for typedefs inheritance problem, 'using' not working.

J

jleslie48

Its probably something silly, but I'm trying to make a generic
namespace for my defined types. In this example its an enum that I
want several classes in a different namespace to be able to see.
This is what I wrote:


//++++++++++++++++++++++++++++++++++++++++

namespace MyTypedefs
{
public class MyTypedefsClass
{
public enum indx_type {a, c };
}
}//namespace MyTypedefs


namespace WindowsFormsApplication01
{
using MyTypedefs;

public partial class Form1 : Form
{


MyTypedefs.MyTypedefsClass.indx_type indx;

indx_type indx_bad;


//++++++++++++++++++++++++++++++++++++++++

now two things are bad:

1) can comment out the "using using MyTypedefs;" line and nothing
changes. which brings me to the second problem,

2) the last line "indx_type indx_bad; " is an error message
undefined type.

I was hoping that the using line would allow me to use the indx_type
directly, similar to how a included .h file allows a c programmer to
know about a type that is defined withing the h file.
 
A

Arne Vajhøj

Its probably something silly, but I'm trying to make a generic
namespace for my defined types. In this example its an enum that I
want several classes in a different namespace to be able to see.
This is what I wrote:


//++++++++++++++++++++++++++++++++++++++++

namespace MyTypedefs
{
public class MyTypedefsClass
{
public enum indx_type {a, c };
}
}//namespace MyTypedefs


namespace WindowsFormsApplication01
{
using MyTypedefs;

public partial class Form1 : Form
{


MyTypedefs.MyTypedefsClass.indx_type indx;

indx_type indx_bad;


//++++++++++++++++++++++++++++++++++++++++

now two things are bad:

1) can comment out the "using using MyTypedefs;" line and nothing
changes. which brings me to the second problem,

2) the last line "indx_type indx_bad; " is an error message
undefined type.

I was hoping that the using line would allow me to use the indx_type
directly, similar to how a included .h file allows a c programmer to
know about a type that is defined withing the h file.

using MyTypedefs;

should allow you to shorten:

MyTypedefs.MyTypedefsClass.indx_type indx;

to:

MyTypedefsClass.indx_type indx;

Arne
 
J

jleslie48

using MyTypedefs;

should allow you to shorten:

MyTypedefs.MyTypedefsClass.indx_type indx;

to:

MyTypedefsClass.indx_type indx;

Arne

well my first problem was that the first namespace can't be
MyTypedefs !!!
that will mess up the IDE so bad you have to shut it down and
restart.

you are correct, your solution worked, but it is second best to what I
wanted. It turned out all I have to do is put indx_type outside the
class, but inside the namespace. the following code works fine, I
used indx_type2 for the namespace solution, and the original indx_type
as a "global to the namespace WindowsformsApplicaoint01" type:


//+++++++++++++++++++++++++
namespace WindowsFormsApplication01
{
using MyTypedefs;
public enum indx_type {a, c };

public partial class Form1 : Form
{


MyTypedefs.MyTypedefsClass.indx_type2 indx2;

MyTypedefsClass.indx_type2 indx2a;

indx_type indx;

//+++++++++++++++++++++++++++++++++++++++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top