CLR Class Library
In my head file:

using namespace System;
using namespace System::Xml;
using namespace System::Net::Mail;
namespace CPTest {

public ref class clsSendMail
{
public:
void getMailMessage(String^ v_Content);
void doSendMail();
private:
String^ v_MailContent;
MailMessage objMailMessage;
};
}

In my cpp File:

#include "stdafx.h"
#include "CPTest.h"
void getMailMessage(String^ v_Content)
{
objMailMessage= gcnew MailMessage("aa@aa.aa","aa@aa.aa","test
mail",v_Content);
return ;
}
..............

my question is :
1.why compiler told me "'objMailMessage' : undeclared identifier"?
2.In .Net class, when define an object of System::String. i have a problem
just like this below.
(for example:
"String^ a;" is correct.
But why "String a;" is wrong.)

thanks.

RE: i'm a C++ beginer and i have a question. by bruno_nos_pam_van_dooren

bruno_nos_pam_van_dooren
Tue Oct 24 03:23:01 CDT 2006

> CLR Class Library
> In my head file:
>
> using namespace System;
> using namespace System::Xml;
> using namespace System::Net::Mail;
> namespace CPTest {
>
> public ref class clsSendMail
> {
> public:
> void getMailMessage(String^ v_Content);
> void doSendMail();
> private:
> String^ v_MailContent;
> MailMessage objMailMessage;
> };
> }
>
> In my cpp File:
>
> #include "stdafx.h"
> #include "CPTest.h"
> void getMailMessage(String^ v_Content)
> {
> objMailMessage= gcnew MailMessage("aa@aa.aa","aa@aa.aa","test
> mail",v_Content);
> return ;
> }
> ..............
>
> my question is :
> 1.why compiler told me "'objMailMessage' : undeclared identifier"?

Because your implementation of getMailMessage is a plain function, the way
you define it. That should be clsSendMail::getMailMessage. Otherwise the
compiler does not know that your definition of getMailMessage is the
implementation of that class method.

> 2.In .Net class, when define an object of System::String. i have a problem
> just like this below.
> (for example:
> "String^ a;" is correct.
> But why "String a;" is wrong.)

Because strings are allocated on the managed heap. 'a' can only be a
reference to a string (^), 'a' cannot be the string itself, since that does
not live on the stack.

--
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"


Re: i'm a C++ beginer and i have a question. by Tamas

Tamas
Wed Oct 25 12:18:29 CDT 2006

Lorry Astra wrote:

> 2.In .Net class, when define an object of System::String. i have a problem
> just like this below.
> (for example:
> "String^ a;" is correct.
> But why "String a;" is wrong.)

See http://tinyurl.com/yefh5c

Please read what Kapil Khosla [MSFT] replied.

Tom