|
v.j wrote: thanks in advance.
You're welcome, in retrospect.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can use of Invalidate.
|
|
|
|
|
The messages generated by the system should handle that.
Please don't reinforce this poor posting behavior!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok. 
|
|
|
|
|
hello everyone;
please tell me "How to add button to CListCtrl ?"
thanks in advance.
|
|
|
|
|
hi,
why r u post ur thread in my thread ,
please post it in new thread for relevant answers.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Hi all,
I am trying to initialize an object using it's constructor, but the members of the object are just not getting initialized.I will just explaining it to you with some coding so that you can understand my issue in a better way.
I have a base class ,say CBase and I am deriving a class from it ,say Derived.
<br />
Base<br />
----<br />
class CBase<br />
{<br />
int nBmember1;<br />
int nBmember2;<br />
<br />
public:<br />
CBase(int nBmember1,int nTempMember):nBmember1(nBmember1),nBmember2(nTempMember){}<br />
<br />
<br />
};<br />
<br />
Derived<br />
-------<br />
class CDerived :public CBase<br />
{<br />
int nDmember1;<br />
public:<br />
CDerived(int nBmember1,int nTempMember,int nTempMember2):CBase(nBmember1,nTempMember),nDmember1(nTempMember){}<br />
<br />
};<br />
<br />
int main()<br />
{<br />
CDerived *DerivedObj= new CDerived(25,50,75);<br />
}<br />
<br />
While creating an object passing these parameters ,It goes to the derived class constructor,the derived class constructor in turn calls the Base class constructor with their respective arguments.But these values are not being assigned to the members of the class.
while I access the DerivedObj , it has some junk value for its members..
I don't have any clue on why the object is not getting initialized with the correct values? Have anyone of you come across an issue like this?
Please help.... 
|
|
|
|
|
cydd wrote: nBmember1(nBmember1),
your formal parameter and member variable are having same name in the base class,
If you follow naming conventions like "m_" prefix for member variable, this type of programming errors can be avoided.
cydd wrote: (int nBmember1,int nTempMember,int nTempMember2):CBase(nBmember1,nTempMember),nDmember1(nTempMember){}
nTempMember2 is ununsed. always compile with highest warning level and don't ignore warnings, i prefer consider warning as error. unreferenced variable is easily caught by compiler.
modified on Saturday, March 8, 2008 6:06 AM
|
|
|
|
|
Thanks for ur response Rajkumar.
I appreciate ur suggestion.
However I tried using different names for the formal parameters, it's not working.
The warning level is 4 which is the maximum ..
But it doesnt show any kind of warning for this.
One more thing,I have used pragma pack(1) in the header file. if this could help you in assisting me.
Thanks
|
|
|
|
|
i am new learner for visual c++6.hi..i know this question sounds like stupid, but there is nobody that surrounding me i can ask. i had already found the other people program at
http://www.ucancode.net/Visual_C_MFC_Example/Create-2d-bar-line-pie-chart-vc-example.htm
however, there are a few things that i am not sure about it. can someone help me to solve it? what is it mean by m_pGraphObject1 and ID_OBJECT_GRAPH_1 and where should i type all those command in the program? the example given is in the pie chart, how to do for the line graph? i really know nothing about the programmiing, but i have to submit my work at the end of March..Hope somebody that is kind can help me with ths..thanks..
llf
|
|
|
|
|
m_pGraphObject1 is an instance of CGraphObject class. If you want to use it then you need to download the corrensponding source files and include them in your project.
Member 4773877 wrote: the example given is in the pie chart, how to do for the line graph?
Since you're not experienced I suggest you to download the demo project, have a look at code and start to try little changes.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
thanks for your help...do you mean that i have to refer to the 2DLineGraph.cpp file in order to modify the course code?
llf
|
|
|
|
|
Hello everyone,
We have a lot of discussion in the two days, seems points from people are not quite the same (at least to some degree). Let me quote the original statement from Bjarne and code again here.
My question is,
1. if you agree g(int) -- declaration only -- will not instantise function f to f<int>, which conflicts with Bjarne's point, could you provide some code to prove please?
2. if you agree with Bjarne's points, g(int) -- declaration only -- will instantise function f to f<int>, could you also provide some code to prove please?
My point is (1), since I think VC instantise a template only when we use it other than deduce any information from template definition phase -- but I can not prove it. If you could prove (1), it is great!
template <class T> void f (T a) { g(a); }
void g(int);
void h()
{
extern g (double);
f (2);
}
--------------------
the point of instantiation for f<int>() is just before h(), so the g() called in f() is the global g (int) rather than the local g (double).
--------------------
BTW: from above statement from Bjarne, I think he means declaration of g(int) before h() will instiatise f to f <int>.
thanks in advance,
George
|
|
|
|
|
i didn't read you discussion.
George_George wrote: 2. if you agree with Bjarne's points, g(int) -- declaration only -- will instantise function f to f<int>,
yes, i agree with bjarne's point
AFAIU, template instantiation is compile time process, declaration is sufficient for compiler to deduce a template function. with "not declaration" you mean definition of function g(int), if not defined linker will catch the unresolved symbol, but in the compilation time itself template instantiation happens, declaration is sufficient. (except the case of inline function, where definition should be visible at compile stage).
George_George wrote: could you also provide some code to prove please?
your example is quite enough to prove, just compile the code (don't build, i mean don't link), the code successfully compiles.
|
|
|
|
|
Thanks Rajkumar,
Rajkumar R wrote: your example is quite enough to prove, just compile the code (don't build, i mean don't link), the code successfully compiles.
I think you mean the sample in my original question, right? If yes, why if compile successful implies f is instantised by g(int) declaration other than f(2) inside h()? How do you prove it?
regards,
George
|
|
|
|
|
George_George wrote: I think you mean the sample in my original question, right?
yes.
George_George wrote: why if compile successful implies f is instantised by g(int) declaration other than f(2) inside h()?
I would reformat this phrase,
if compile successful implies, at the point of function template instantiation 'void f<int> (T)' (i.e f(2) inside h()) being compiled g(a) is deduced to g(int), whose declaration is in the nearest global( or namespace, if called by scope resolution operator) scope.
actually f(2) in h() is used instantiate the template function f(T), where <T> is deduced to <int>
|
|
|
|
|
Thanks Rajkumar,
1.
I think you mean f(2) inside h will instantise template function f, right?
2.
When do you think g(int) will be bound to template function f? During the time of instantiation or during the time of compiler parsing definition of template function f?
(discuss in MSVC context and behavior is fine)
regards,
George
|
|
|
|
|
When a function template is first called for each type (f(2) in h), the compiler creates a version of the templated function specialized for the type 'void f<int> (T)', which is called Function .template instantiation [^].
1) yes, see above.
2)
George_George wrote: During the time of instantiation or during the time of compiler parsing definition of template function f?
see above, without parsing the template function f, how it can create a version of that function, called instantiation.
As a side note function template instantiation requires the definition of the template function to be visible ( f<T> ) at the point where it is refered in the code (i.e when calling template function), may be you confused this with the definition of g() with is non-template function. declaration of g() is sufficient for calling g() to be compiled, which applicable to non-template context also.
And question, declaration of g() will instantise f<int> (T) is true. since g is non inline non template function.
try commenting the declaration of g(); you will get compilation error, identifier g, not found when instantiating funtion void f<int>(T), otherwise not; this is the proof.
|
|
|
|
|
Thanks Rajkumar,
1.
I studied your recommended link and it is great. I found some knowledge which I do not have before. Previously, I think only use of the template function will trigger its instantiation, but now I have found at least two ways to explicitly instantise template function, besides the "use of the template function methods". The two methods are,
template<class T> void f(T) { }
template void f<int> (int);
2.
Rajkumar R wrote: And question, declaration of g() will instantise f<int> (T) is true. since g is non inline non template function.
try commenting the declaration of g(); you will get compilation error, identifier g, not found when instantiating funtion void f<int>(T), otherwise not; this is the proof.
I have tried the following code will not cause any compile errors, using Visual Studio 2008. I doubt whether the declaration of g will trigger the instantiation of template function f?
template <class T> void f(T a) {g (a);}
void g (int a);
regards,
George
|
|
|
|
|
Ahh, Now i read your orginal post and understand the question, i actually missed the following
George_George wrote:
the point of instantiation for f<int>() is just before h(), so the g() called in f() is the global g (int) rather than the local g (double).
--------------------
BTW: from above statement from Bjarne, I think he means declaration of g(int) before h() will instiatise f to f <int>.
I understand from the bjarne's statement is that the point of instantiation is at the template function declaration template <typename T> void f (T) which is before the function h() which is instantised by f<int>() call in h(), since the template deduce functions at the global or namespace scope global g() is taken rather than local g(double).
g(int) won't trigger instantiation of f<int>(), template function instantiation occurs when it is called by special type template arguments. All that reply before was keeping in mind f<int> () is instantiated with g(int) triggered by the call f(int) in h.
|
|
|
|
|
Thanks Rajkumar!
I found after discussion with you these days, most of my confusions are solved. Cool!!
But still one confusion can not be solved, I show my confusion in below code.
I do not know why there is compile error below (compile error posted), and if I remove statement "cout << d.get_i() << endl; // output 200", there will not be any compile errors?
My confusion is, I think whether or not we call get_i, Derived<int> is instantised, right? Instantised means having the same code, why whether we call a member function or not will impact compile result? Is there some new rules we do not cover theses days about instantiation of template class?
Compile errors,
1>------ Build started: Project: test_template4, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(15) : error C2955: 'Base' : use of class template requires template argument list
1> d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(5) : see declaration of 'Base'
1> d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(21) : see reference to class template instantiation 'Derived<T>' being compiled
1>d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(15) : error C2955: 'Base' : use of class template requires template argument list
1> d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(5) : see declaration of 'Base'
1> d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(26) : see reference to class template instantiation 'Derived<T>' being compiled
1> with
1> [
1> T=int
1> ]
#include <iostream>
using namespace std;
template <typename T> struct Base {
public:
Base (int _i): i (_i)
{
}
int i;
};
template <typename T> struct Derived : public Base {
public:
Derived (int _i) : Base<T> (_i)
{
}
int get_i() { return i; }
};
int main()
{
Derived<int> d (200);
cout << d.get_i() << endl;
return 0;
}
regards,
George
|
|
|
|
|
George_George wrote: Is there some new rules we do not cover theses days about instantiation of template class?
I think yes, in this thread we discussed about function template, please refer Class Template Instantiation
[^] and note the following from the link
"No code is generated for a templated class or function until it is instantiated.
Moreover, member functions are instantiated only if they are called"
|
|
|
|
|
Cool, Rajkumar!
Question answered.
regards,
George
|
|
|
|
|
Hello everyone,
For the MSDN template sample,
http://msdn2.microsoft.com/en-us/library/w98s4hs8.aspx
My questions are,
1. does void [Code]f(char) { printf_s("f(char)\n");}[/Code] or [Code]g('c');[/Code] instantise function g to parameter type char?
2. "This can cause overloads to be declared after the template (but before the template is instantiated) to be seen." What does this mean?
thanks in advance,
George
|
|
|
|
|
When template is declared, the compiler takes into account also the char overload of the function N::f and it shouldn't (because it is declared after template declaration itself: please note I wasn't aware about this rule).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|