|
George_George wrote: Do you mean your version of book is using the below code? If yes,
Could you please do not ask that many times of yes/no?! I have already asnwered "yes" in my previous reply.
George_George wrote: error C2660: 'Container::sort' : function does not take 1 arguments
Visual C++ has problem with ISO/IEC 14882 standard. That's all.
You can try other compilers.
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
Thanks and I have got a 3rd edition book to have a common page with you to discuss.
You can compile the following code? I am confused, the following code violates C++ rule, you can see when we invoke sort (v) inside sort member function of class Container, there is no matched function. So, it can not compile. Any comments?
#include <vector>
using namespace std;
template <class T> void sort (vector <T >& v )
{
sort (v.begin(), v.end());
}
class Container {
vector <int> v;
public :
void sort()
{
sort(v);
}
};
regards,
George
|
|
|
|
|
George_George wrote: Any comments? Do you agree with me and think his sample is wrong?
So then why don't you take that up with Dr. Stroustrup rather than bothering us with your disagreements?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
How do you understand Bjarne's comments and related sample as I quoted in the original question? If you understand, it is appreciated if you could share your points here.
regards,
George
|
|
|
|
|
Hello everyone,
I am confused about what Bjarne means below, and I quoted the section name, his words and his sample.
My question is, what did he mean "A call that by coincidence has an argument that matches an actual template parameter type is not dependent"?
I think the compile error is because, g (1) function call is not dependent on template parameter, and it should be resolved in the definition phase (not instantiation phase) of template function f. But in definition phase of f, what g is (the symbol g) can not be resolved. So comes the compile error.
Is my analysis correct? What did Bjarne mean?
(section C.13.8.1 Dependent Names)
--------------------
A call that by coincidence has an argument that matches an actual template parameter type is not dependent. For example,
--------------------
template <class T> T f (T a)
{
return g (1);
}
int g (int);
int z = f (2);
thanks in advance,
George
|
|
|
|
|
I've started up Excel and read and posted to spreadsheets using MFC in VC++, but whenever I try to do something new, like draw a chart, it takes me an age to locate the classes and methods I need to do it. Where can I find a good reference on all the classes and methods?
Fred Andres
|
|
|
|
|
Sadly, MSDN doesn't have as much help as it used to, the MSDN that came with VC6 is probably your best bet, if you can get it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
For Excel 2003, see C:\Program Files\Microsoft Office\OFFICE11\1033\VBAXL10.chm or C:\Program Files\Microsoft Visual Studio\MSDN\2001OCT\1033\VBAXL10.chm.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Right, well. I have a struct which so far contains just a char* and a vector of the struct.
Now, i have a function that adds a new item to my vector which takes a char* which is used to initialise my struct:
void AddItem(char* ItemName)
{
myStruct newItem(ItemName);
myVector.push_back(newItem);
}
In the struct constructor i used strcpy to copy the contents of the string rather than the pointer, and i also made a copy constructor which uses strcpy again when copying the struct.
But still, once we leave the function (or should i say, the function in which this function was called) the item, disappears. Debuging it i can see that the item is added and then once we get out of the functions simply vanishes, and i don't understand why.
So, any help of course, would be greatly appreciated.
My current favourite word is: Nipple!
-SK Genius
modified on Sunday, March 9, 2008 8:37 PM
|
|
|
|
|
AddItem() is just a global scoped function? Or is it a method of a class?
What, then, is myVector? What does the myStruct structure declaration look like?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AddItem is a method of a class.
The whole structure is kind like this:
int main()
{
Class1 myClass;
Class2 myOtherClass;
Class2.DoStuff(myClass);
}
...
Class2::DoStuff(Class1 firstClass)
{
char* text = "SomeText";
firstClass.AddItem(text);
}
It is of course quite different, but its basically the same thing.
The struct looks kinda like this:
struct myStruct
{
public:
char* Name;
myStruct(char* name)
{
Name = new char[100];
strcpy(Name, name);
}
}
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
SK Genius wrote: Class2::DoStuff(Class1 firstClass)
If you are really passing objects by value like that then the scope of
those objects only lasts for the DoStuff() call. After it returns, your original
objects remains untouched.
Maybe you meant to pass it by reference?
Class2::DoStuff(Class1 <font color="Red">&</font>firstClass)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Its actually passed by a pointer... hmm. This is what really happens:
Class Object
{
virtual void DoAction(void** args);
}
Class Player : public Object
{
void AddItem(char* ItemName);
void SomeFunction();
}
Player::SomeFunction()
{
int dir = 5;
Object* myObj = GetObjectFromSomewhere();
void** temp = new void*[2];
temp[0] = &dir;
temp[1] = this;
}
Class NPC : public Object
{
void DoAction(void** args);
}
void NPC::DoAction(void** args)
{
int dir = *(int*)args[0];
Player player = *(Player*)args[1];
}
Then of course, i used the non-pointery player object to work on. Thats the problem isn't it?
The only reason i didn't just use the pointer was because i already had alot of code with just the player.stuff rather than player->stuff
I figured it would save time. I guess not.
Oh well, lesson learned.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
SK Genius wrote: i used the non-pointery player object to work on. Thats the problem isn't it?
On this line you mean?
Player player = *(Player*)args[1]; If so, then yes - you're working with a new Player object copied from the passed object...
Any changes made to the new object won't be reflected in the original.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
I've written an application in VC++ newly and it worked well while being in debug mode. But when tring it in release version, I get an error message that says:
"An unsupported operation was attempted."
My app loads a dialog box from a DLL. After spending and wasting(!) a lot of time, I found the error occurs in "DoDataExchange" function in the following line:
"DDX_Control(pDX, IDC_DLL_EDIT_WRD, m_ctlWord);"
Please don't let my app to become waste!
Thanks...
|
|
|
|
|
And what was the error?
Moreover, I've you read here and here?
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
|
|
|
|
|
Because Control is not exist corresponding to IDC_DLL_EDIT_WRD ID.
|
|
|
|
|
Add a virtual function like clone() ?
-------------------------------------
How to write the copy constructor of class NeedCopyConstruct ,
NeedCopyConstruct::m_list might contain Base and Derived
pointers.
class Base
{
public:
Base(const Base &base);
}
class Derived : public Base
{
public:
Derived(const Derived &derived);
}
class NeedCopyConstruct
{
public:
NeedCopyConstruct(const NeedCopyConstruct &ncc);
CTypedPtrArray<cobarray,base*> m_list;
}</cobarray,base*>
modified on Sunday, March 9, 2008 11:54 AM
|
|
|
|
|
Exploit polymorphism: implement a virtual member, say clone (basically a copy-constructor), for both Base and Derived class and use it to copy list members.
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
|
|
|
|
|
followait wrote: Add a virtual function like clone()?
I guess you modified to add the above, and you want some other method to call the copy constructor.
I assume, if m_list contains Base and derived pointers means your list holds a single type may be "Base *. I assume your base class destructor is virtual destructor other wise you end up not calling derived class destructor if it is derived object and pointer is base.
If you have any virtual function, possibly atleast virtual destructor, then you can use the runtime type information to call the copy constructor,
Base *pObj = new Derived();
Base *pObjClone = NULL;
const type_info& typeInfo = typeid(*pObj);
if (typeid(Derived) == typeInfo)
{
pObjClone = new Derived(( Derived & )*pObj);
}
else if (typeid(Base) == typeInfo)
{
pObjClone = new Base(( Base & )*pObj);
}
else
{
}
Note: if you don't have virtual destructor, deleting the list item may have memory leak.
this method can be used if your class have any virtual function and you don't want to change the code to add clone() method.
if you don't have virtual functions and don't want to add clone method, may be storing type (enumerated values) along with the pointer in the list, or separte list for each type can be used.
if you are free to add virtual functions, Clone() method will be the right choice.
|
|
|
|
|
How to make a standalone EXE(with all libraries included) file in Visual Studio 1998!
In Visual Studio 2005, there is an option but I can't find one in Visual Studio 1998!
Please help me out!
|
|
|
|
|
ddspliting wrote: Visual Studio 1998
Another custom version of Visual Studio!
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
|
|
|
|
|
Project/Setting/General/Microsoft Foundation Classes: Use MFC in a Static Library
|
|
|
|
|
Its not working in Visual Studio 6(1998).It has only option of USE MFC in share DLL! and not static DLL unlike Visual Studio 2005!
Please if there is any other way???
|
|
|
|
|
You're wrong: Visual Studio 6 allows to link statically with MFC .
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
|
|
|
|