Oleg_SK
05-06-2010, 13:52
Сабж. Сейчас программа выглядит так:
//virtual.h
class One
{
public:
One(){};
virtual ~One();
virtual void TellMe()=0;
protected:
private:
};
class Two: public One
{
public:
~Two();
virtual void TellMe();
protected:
private:
};
class Three: public One
{
public:
~Three();
protected:
virtual void TellMe();
private:
};
//virtual.cpp
#include "stdafx.h"
#include <iostream>
#include "virtual.h"
using namespace std;
One::~One()
{
cout << "!!!" << endl;
}
Two::~Two()
{
cout << "Two::destructor" << endl;
}
void Two::TellMe()
{
cout << "Two::TellMe" << endl;
}
Three::~Three()
{
cout << "Three::destructor" << endl;
}
void Three::TellMe()
{
cout << "Three::TellMe" << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
const int size=10;
One* arrey[size];
for(int i=0; i<size; i+=2)
{
arrey[i]=new Two;
arrey[i+1]=new Three;
}
Three* temp;
for(int i=0; i<size; ++i)
{
//temp = dynamic_cast<Three*>(arrey[i]);
//if(temp!=NULL)
//{
// cout << "Three object...\n";
// temp->TellMe();
//}
arrey[i]->TellMe();
}
cout << endl;
for(int i=0; i<size; ++i)
{
delete arrey[i];
}
cout << endl;
int y;
cin >> y;
return 0;
}
Хочу выделить классы в отдельные файлы, но что-то не получается (лезут непонятные ошибки)... Делаю так:
//One.h
class One
{
public:
One(){};
virtual ~One();
virtual void TellMe()=0;
protected:
private:
};
//One.cpp
#include <iostream>
#include "One.h"
using namespace std;
One::~One()
{
cout << "!!!" << endl;
}
//Two.h
#include "One.h"
class Two: public One
{
public:
~Two();
virtual void TellMe();
protected:
private:
};
//Two.cpp
#include <iostream>
#include "Two.h"
using namespace std;
Two::~Two()
{
cout << "Two::destructor" << endl;
}
void Two::TellMe()
{
cout << "Two::TellMe" << endl;
}
//Three.h
#include "One.h"
class Three: public One
{
public:
~Three();
virtual void TellMe();
protected:
private:
};
//Three.cpp
#include <iostream>
#include "Three.h"
using namespace std;
Three::~Three()
{
cout << "Three::destructor" << endl;
}
void Three::TellMe()
{
cout << "Three::TellMe" << endl;
}
//virtual.cpp
#include "stdafx.h"
#include <iostream>
#include "One.h"
#include "Two.h"
#include "Three.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int size=10;
One* arrey[size];
for(int i=0; i<size; i+=2)
{
arrey[i]=new Two;
arrey[i+1]=new Three;
}
//Three* temp;
for(int i=0; i<size; ++i)
{
//(dynamic_cast<Three*>(arrey[i]))->TellMe();
//temp = dynamic_cast<Three*>(arrey[i]);
//if(temp!=NULL)
//{
// cout << "Three object...\n";
// temp->TellMe();
//}
arrey[i]->TellMe();
}
//Three test;
//test.TellMe();
cout << endl;
for(int i=0; i<size; ++i)
{
delete arrey[i];
}
cout << endl;
int y;
cin >> y;
return 0;
}
Хотелось бы узнать: что я делаю не так?
P.S: Использую Visual Studio 2010.
//virtual.h
class One
{
public:
One(){};
virtual ~One();
virtual void TellMe()=0;
protected:
private:
};
class Two: public One
{
public:
~Two();
virtual void TellMe();
protected:
private:
};
class Three: public One
{
public:
~Three();
protected:
virtual void TellMe();
private:
};
//virtual.cpp
#include "stdafx.h"
#include <iostream>
#include "virtual.h"
using namespace std;
One::~One()
{
cout << "!!!" << endl;
}
Two::~Two()
{
cout << "Two::destructor" << endl;
}
void Two::TellMe()
{
cout << "Two::TellMe" << endl;
}
Three::~Three()
{
cout << "Three::destructor" << endl;
}
void Three::TellMe()
{
cout << "Three::TellMe" << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
const int size=10;
One* arrey[size];
for(int i=0; i<size; i+=2)
{
arrey[i]=new Two;
arrey[i+1]=new Three;
}
Three* temp;
for(int i=0; i<size; ++i)
{
//temp = dynamic_cast<Three*>(arrey[i]);
//if(temp!=NULL)
//{
// cout << "Three object...\n";
// temp->TellMe();
//}
arrey[i]->TellMe();
}
cout << endl;
for(int i=0; i<size; ++i)
{
delete arrey[i];
}
cout << endl;
int y;
cin >> y;
return 0;
}
Хочу выделить классы в отдельные файлы, но что-то не получается (лезут непонятные ошибки)... Делаю так:
//One.h
class One
{
public:
One(){};
virtual ~One();
virtual void TellMe()=0;
protected:
private:
};
//One.cpp
#include <iostream>
#include "One.h"
using namespace std;
One::~One()
{
cout << "!!!" << endl;
}
//Two.h
#include "One.h"
class Two: public One
{
public:
~Two();
virtual void TellMe();
protected:
private:
};
//Two.cpp
#include <iostream>
#include "Two.h"
using namespace std;
Two::~Two()
{
cout << "Two::destructor" << endl;
}
void Two::TellMe()
{
cout << "Two::TellMe" << endl;
}
//Three.h
#include "One.h"
class Three: public One
{
public:
~Three();
virtual void TellMe();
protected:
private:
};
//Three.cpp
#include <iostream>
#include "Three.h"
using namespace std;
Three::~Three()
{
cout << "Three::destructor" << endl;
}
void Three::TellMe()
{
cout << "Three::TellMe" << endl;
}
//virtual.cpp
#include "stdafx.h"
#include <iostream>
#include "One.h"
#include "Two.h"
#include "Three.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int size=10;
One* arrey[size];
for(int i=0; i<size; i+=2)
{
arrey[i]=new Two;
arrey[i+1]=new Three;
}
//Three* temp;
for(int i=0; i<size; ++i)
{
//(dynamic_cast<Three*>(arrey[i]))->TellMe();
//temp = dynamic_cast<Three*>(arrey[i]);
//if(temp!=NULL)
//{
// cout << "Three object...\n";
// temp->TellMe();
//}
arrey[i]->TellMe();
}
//Three test;
//test.TellMe();
cout << endl;
for(int i=0; i<size; ++i)
{
delete arrey[i];
}
cout << endl;
int y;
cin >> y;
return 0;
}
Хотелось бы узнать: что я делаю не так?
P.S: Использую Visual Studio 2010.