主题:关于类的申明和实现分开的问题
类的申明部分
头文件one.h的代码:
#pragma once
using namespace System;
__gc public class one
{
private:
String* var;
public:
one(void);
void display(void);
};
————————————————————
实现部分
one.cpp代码:
#include "StdAfx.h"
#include ".\one.h"
#using <mscorlib.dll>
one::one(void)
{
}
void one::display(void)
{
this->var = S"hello";
Console::WriteLine(this->var);
}
————————————————————
主函数的代码:
#include "stdafx.h"
#include "one.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
one* One;
One->display();
return 0;
}
——————————————————
[color=FF0000][size=1]编译成功,但是为什么一运行就出错??[/size][/color]
[em6]
头文件one.h的代码:
#pragma once
using namespace System;
__gc public class one
{
private:
String* var;
public:
one(void);
void display(void);
};
————————————————————
实现部分
one.cpp代码:
#include "StdAfx.h"
#include ".\one.h"
#using <mscorlib.dll>
one::one(void)
{
}
void one::display(void)
{
this->var = S"hello";
Console::WriteLine(this->var);
}
————————————————————
主函数的代码:
#include "stdafx.h"
#include "one.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
one* One;
One->display();
return 0;
}
——————————————————
[color=FF0000][size=1]编译成功,但是为什么一运行就出错??[/size][/color]
[em6]