Click here to Skip to main content
15,917,731 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Static library with MFC support Pin
Erudite_Eric15-Aug-13 23:13
Erudite_Eric15-Aug-13 23:13 
GeneralRe: Static library with MFC support Pin
Richard MacCutchan15-Aug-13 23:18
mveRichard MacCutchan15-Aug-13 23:18 
GeneralRe: Static library with MFC support Pin
Erudite_Eric16-Aug-13 1:26
Erudite_Eric16-Aug-13 1:26 
GeneralRe: Static library with MFC support Pin
Richard MacCutchan16-Aug-13 1:33
mveRichard MacCutchan16-Aug-13 1:33 
GeneralRe: Static library with MFC support Pin
Erudite_Eric16-Aug-13 22:57
Erudite_Eric16-Aug-13 22:57 
GeneralRe: Static library with MFC support Pin
Richard MacCutchan16-Aug-13 23:11
mveRichard MacCutchan16-Aug-13 23:11 
AnswerRe: Static library with MFC support SOLVED Pin
Vaclav_17-Aug-13 3:11
Vaclav_17-Aug-13 3:11 
QuestionA template question Pin
EQ Learner13-Aug-13 9:50
EQ Learner13-Aug-13 9:50 
I am practicing c++ template programming and got a very confusing question. My purpose is to write a program to output the data of classes. If the the class is an POD (plain old data), use a global function (say Serialize) for output, if it's not, use the class's own Serialize function (assume every non-pod class in this program has implemented its own Serialize method). To better illustrate this idea, I have a little program to do that:

C++
#include <assert.h>
#include <iostream>

using namespace std;

class myclass
{
public:
	myclass(void):_nID(10) { _nOldID = _nID; };

	void Serialize(std::ostream &os)	
	{
		os << _nID;
	}

	void Serialize(std::istream &is)
	{
		is >> _nOldID;
	}

private:
	int _nID, _nOldID;
};

template <typename T>
void Serialize(std::ostream &os, const T& Obj)
{
	os << Obj;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
int main(int argc, char* argv[])
{
//	typedef myclass	T;
	typedef unsigned int	T;
	T Obj;

	// Do some initialization for Obj

	if (!std::is_pod<T>::value)			// T is not a POD
	{
		std::cout << "T != POD";
		Obj.Serialize(cout);			// Use its own serializer
	}
	else								// T is a POD
	{
		Serialize(cout, Obj);			// Use default global serializer
		std::cout << "T = POD";
	}

	return 0;
}


The problem is that the compiler giving an error that error C2228: left of '.Serialize' must have class/struct/union in the if clause, which I think it shouldn't because T is defined as unsigned int which is of POD type. On the other hand, if T is defined as myclass, the compiler complains the global Serialize function saying "binary '<<' : no operator found which takes a right-hand operand of type 'const T' (or there is no acceptable conversion)", which is in the "else" clause which should not be reached.

Anybody can explain this?
AnswerRe: A template question Pin
pasztorpisti13-Aug-13 12:22
pasztorpisti13-Aug-13 12:22 
GeneralRe: A template question Pin
EQ Learner14-Aug-13 4:08
EQ Learner14-Aug-13 4:08 
GeneralRe: A template question Pin
pasztorpisti14-Aug-13 5:21
pasztorpisti14-Aug-13 5:21 
GeneralRe: A template question Pin
EQ Learner14-Aug-13 5:55
EQ Learner14-Aug-13 5:55 
GeneralRe: A template question Pin
pasztorpisti14-Aug-13 6:03
pasztorpisti14-Aug-13 6:03 
GeneralRe: A template question Pin
EQ Learner14-Aug-13 6:13
EQ Learner14-Aug-13 6:13 
GeneralRe: A template question Pin
pasztorpisti14-Aug-13 8:29
pasztorpisti14-Aug-13 8:29 
GeneralRe: A template question Pin
EQ Learner14-Aug-13 8:57
EQ Learner14-Aug-13 8:57 
GeneralRe: A template question Pin
pasztorpisti14-Aug-13 9:29
pasztorpisti14-Aug-13 9:29 
Questionhow can i improve my c programming in different ways Pin
Member 985748713-Aug-13 2:18
Member 985748713-Aug-13 2:18 
AnswerRe: how can i improve my c programming in different ways Pin
NotPolitcallyCorrect13-Aug-13 2:29
NotPolitcallyCorrect13-Aug-13 2:29 
AnswerRe: how can i improve my c programming in different ways Pin
CPallini13-Aug-13 2:32
mveCPallini13-Aug-13 2:32 
JokeRe: how can i improve my c programming in different ways Pin
pasztorpisti13-Aug-13 3:29
pasztorpisti13-Aug-13 3:29 
AnswerRe: how can i improve my c programming in different ways Pin
pasztorpisti13-Aug-13 3:15
pasztorpisti13-Aug-13 3:15 
GeneralRe: how can i improve my c programming in different ways Pin
Erudite_Eric13-Aug-13 4:33
Erudite_Eric13-Aug-13 4:33 
GeneralRe: how can i improve my c programming in different ways Pin
CPallini13-Aug-13 9:17
mveCPallini13-Aug-13 9:17 
GeneralRe: how can i improve my c programming in different ways Pin
pasztorpisti13-Aug-13 9:22
pasztorpisti13-Aug-13 9:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.