tags:

views:

80

answers:

2

I'm working on an e-mail app in c++ using .net, and I've run into a problem I can't seem to solve. I'm trying to implement some controller classes. The top chunk is my .h file, the bottom the .cpp file. The errors I'm getting are:

'ComposeMail' : undeclared identifier
'email' : undeclared identifier
syntax error : identifier 'ComposeMail'

It's almost like my include statements aren't working.

Header:

#pragma once
#include "ComposeMail.h"

class MainWindowController{
public:
  MainWindowController(void);
  void ComposeClick(void);
};

Implementation:

#include "StdAfx.h"
#include "MainWindowController.h"

MainWindowController::MainWindowController(void)
{
}

void MainWindowController::ComposeClick(void){
  ComposeMail^ email = gcnew ComposeMail();
}
A: 

Without the code of ComposeMail in ComposeMail.h we cannot really answer.

The compiler says that ComposeMail have not be declared so you have to check the includes to see where it's missing, maybe because of macro-fu or maybe because of a typo error somewhere.

Klaim
A: 

Ok I figured it out...My code constructor for ComposeMail was inside the namespace Firemail (name of our project) so I had to write using namespace FireMail; in my .h file. This worked. Thanks for the answers.

Mike K
Don't put `using namespace` in a header file. `Using namespace` directives are frowned upon. Instead, prefix your class: `FireMail::ComposeMail^ email = gcnew FireMail::ComposeMail();`. This generally increases readability too. If you really want to use a using directive, put it in the `.cpp` file so other source files that include your header aren't affected. Lastly, you could use the other kind of using directive: `using FireMail::ComposeMail`. This only moves one class into the current namespace.
GMan
Thanks for the advice. I'll be sure to do this.
Mike K