Last active
November 28, 2017 10:27
-
-
Save ilwsm/2487514c1f3a3900a5201e57c063c36c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef VELO_HO_H | |
#define VELO_HO_H | |
#include <iostream> | |
template<typename CharType = char> | |
struct UTF8 { | |
typedef CharType Ch; | |
void someMethod(){ | |
std::cout << "someMethod UTF8" << std::endl; | |
} | |
}; | |
template<typename SourceEncoding> | |
class ClassInHeaderOnly { | |
public: | |
typedef typename SourceEncoding::Ch Ch; | |
void print(){ | |
std::cout << "someMethod ClassInHeaderOnly" << std::endl; | |
}; | |
}; | |
class Worked{ ; | |
public: | |
void print(){ | |
std::cout << "someMethod Worked" << std::endl; | |
} | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test1.h" | |
int main() { | |
TestClass aClass; | |
aClass.printHeaderOnlyClass(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test1.h" | |
#include "headeronly.h" | |
TestClass::TestClass() { | |
headerOnly = new ClassInHeaderOnly<UTF8<>>; //шаблон не работает | |
// ClassInHeaderOnly<UTF8<>> *headerOnly2 = new ClassInHeaderOnly<UTF8<>>; //так естественно все работает, но нужен указатель, как член класса. | |
worked = new Worked; //все работает | |
} | |
void TestClass::printHeaderOnlyClass() { | |
headerOnly->print(); //шаблон не работает | |
worked->print(); //все работает | |
} | |
TestClass::~TestClass() { | |
delete (headerOnly); //шаблон не работает | |
delete (worked); //все работает | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef VELO_TEST1_H | |
#define VELO_TEST1_H | |
#include <stdio.h> | |
//#include "headeronly.h" так рабоает, но НЕЛЬЗЯ ! | |
template<typename SourceEncoding> | |
class ClassInHeaderOnly; | |
class Worked; | |
class TestClass { | |
public: | |
TestClass(); | |
virtual ~TestClass(); | |
void printHeaderOnlyClass(); | |
private: | |
ClassInHeaderOnly *headerOnly; //Выбивает ошибку 'ClassInHeaderOnly': use of class template requires template argument list | |
// ClassInHeaderOnly<SourceEncoding> *headerOnly; если так, то 'SourceEncoding': undeclared identifier | |
Worked *worked; //все работает | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment