|
You can make a COM object global with CComObjectGlobal :
CComObjectGlobal<Connection> g_connection;
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
Hi All,
Do I need to initialize in the copy constructor too?
Example:
Foo::foo()
{
*pc = new char[5];
}
Foo::foo(cont foo& f)
{
*pc = new char[5]; // Do I need to do this here too?
Strcpy(this->pc, f.pc);
}
Thanks in advance.
|
|
|
|
|
Assuming your destructor calls delete[] pc , then yes. That is the point of the copy constructor, to make a deep copy when the default behavior of a bitwise copy is insufficient.
BTW, whenever you have a copy constructor, it's a good guideline to also have an operator = as well.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I agree with Mike, however:
Try to avoid this if at all possible - but sometimes it isn't.
Rely upon your lower level tools to ensure copy semantics are enforced properly. In this example rather than using char* try to use std::string, doing so would mean that you wouldn't even have to write the copy constructor. Similarly, rather than using arrays, use std::vector, std::list or std::deque.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
hi guys, i am trying to read in CD info from a file and put it into an array, using a CD class. I have been working here for about 6-8 hours trying to get the input file into an array. i just need some help starting it. It needs to read 15 15 rows with 6 columns in each row. Any help???
thx a bunch.....
#if !defined(microsoft)
#include <stdlib.h>
#define cls() system ("cls");
#endif
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
#include <cstring>
using namespace std;
class CD
{
private:
int numberID1;
char nameArtist[20];
int numSongs;
char genderArtist[10];
float cdPrice;
char artistLabel[25];
char cdArray[15];
public:
CD(); // default constructor
void getData(); //getData
void reportData();
void getkeyedData();
~CD(); //destructor
};
CD::CD()//constructor
{
numberID1 = 0;
nameArtist[0] = '\0';
numSongs = 0;
genderArtist[0] = '\0';
cdPrice = 0;
artistLabel[0] = '\0';
}
CD::~CD()//destructor
{
}
ifstream infile;
ofstream outfile;
ofstream errorlog;
int main ()
{
void instructions();
int menu();
void printCDList(const CD[]);
CD myCD;
CD CDList[50];
int i;
int data_amt;
int response;
outfile.open("cdlist.txt");
errorlog.open("errorlog.txt");
arraytest.open("arraytest.txt");
do
{
char filename[80];
infile.clear();
cout << "Please enter the name of the file with the CD information in it: ";
cin >> filename;
infile.open(filename, ios::in);
}
while (infile.fail());
instructions();
infile>>data_amt;
for(i=1; i<=data_amt; i++)
{
cout << "CD #" << i <<endl;
="" mycd.getdata();
="" getche();
="" cdlist[i]="myCD;
" }=""
="" getche();
="" response="menu();
switch(response)
{
//case" 1:="" mycd.idsort();
="" break;
="" case="" 2:="" mycd.artistsort();
="" break;
case="" 3:="" mycd.getkeyeddata();
="" 4:="" mycd.changeprice();
="" 5:="" mycd.reportdata();
="" cout="" <<="" "printing="" report......"="" endl;
="" "please="" hit="" enter="" to="" finish="" report"="" 6:="" break;
}
="" return="" 0;
}="" end="" of="" main
="" *
="" }
="" if(menuagain[0]="='Y'||menuAgain[0]=='y')
" {
="" menu();
="" else
="" "thank="" you="" for="" using="" this="" program.="" goodbye!"="" endl;
="" 0;
}
="" **********************************************************************
="" function="" name:="" instructions
="" purpose:="" explain="" the="" user="" what="" program="" will="" do
="" parameters:
="" input:
="" input="" &="" output:
="" value:
="" non-local="" variables="" used:
="" functions="" called:
="" **********************************************************************
*=""
void="" instructions()
{
="" "this="" allow="" information="" a="" cd="" from="" keyboard="" and="" file."="" "it="" accept:="" "="" "the="" upc="" code="" on="" cd,="" artist's="" name,="" gender="" artist,="" number="" songs="" price="" label="" that="" released="" cd"="" endl;
}
int="" menu()
{
="" int="" ans;
="" do="" cls();
="" cout<<"choose="" one="" following="" options:"<<endl;
="" cout<<"1.="" sort="" display="" list="" cd's="" by="" id="" number"<<endl;
="" cout<<"2.="" artists="" name"<<="" cout<<"3.="" new="" keyboard"<<endl;
="" cout<<"4.="" change="" cd's"<<endl;
="" cout<<"5.="" create="" report="" sorted="" cout<<"6.="" exit="" program"<<endl;
="" cin="">> ans;
}
while((ans<1)||(ans>6));
return ans;
}
|
|
|
|
|
Welcome to CodeProject, pvparks. Your post is unfortunately too long and hard to read so I doubt you'll get much help.
You need to do a few things. First, put <pre>...</pre> tags around the code to preserve spacing. It's also too much code, you need to narrow it down to just the part that isn't working. Finally, explain what's going wrong. Is it crashing? Giving you the wrong output? Formatting the hard drive?
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Michael Dunn wrote:
Finally, explain what's going wrong. Is it crashing? Giving you the wrong output? Formatting the hard drive?
That'd be funny
How do I print my voice mail?
|
|
|
|
|
Hockey wrote:
That'd be funny
Not for him...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Sorry for a very basic question. I am a student and trying to learn how to add functions from another project to one I am working on. The very simple project is a test MFC project on MS VSC++ 6.0 with default options chosen. I have added the .h and .cpp files from the other project which happens to show a calendar when executed.
After that I am lost. I was told that I would have to add the following code:
AFCYearSelectWnd::create:
But the question is where and how?
All help is greatly appreciated.
John
|
|
|
|
|
In general, you first create the MFC object via Resource Editor, add the C++ code to the project, and link the MFC object to the C++ class.
Kuphryn
|
|
|
|
|
I'm having a rather large issue with Developer Studio where if one types out a varible name such as a class or struct or any other data type, I'm not getting any information from it. That is, when you type pVar. or pVar-> I'm not getting a combobox of information, or if I do, the information is old and is not updating.
Should I reinstall Developer Studio or is this a fix that can be done quickly? One thing and I don't know if this makes a difference. I have VC.NET installed as well. Could they be conflicting with each other?
Thanks!
|
|
|
|
|
|
eventhough the cleanup of NCB will not help you..i strongly recoment you to use VISUAL ASSIST. COOOOOOOL software...thats really great...now i am using the demo version (for vS 6), that will expire soon...
I want to change Myself..Can u help me?
|
|
|
|
|
Try deleting the .ncb file in your project directory (may be corrupt), it will be regenerated by Visual C++. Also, you might want to search for IntelliSense in the MSDN and elsewhere.
INTP
|
|
|
|
|
Replacing the .ncb seemed to fix it. Thanks!
|
|
|
|
|
I had a similar issue before and fixed up the code per instructions given to me, however I still have an issue with it. The code is as follows
<code>
CString CXMLParser::CreateAttributeTag(bool End, CString TagName, COleVariant *Value, ...)
{
va_list argList;
int count = 0;
CString returnVal = _T("");
va_start(argList, Value);
for(;;)
{
CString AttributeName = va_arg(argList, LPCTSTR);
if(AttributeName.IsEmpty()) break;
CString AttributeValue = va_arg(argList, LPCTSTR);
returnVal += AttributeName +"=\'"+ AttributeValue +"\' ";
}
va_end(argList);
return FormatTag(End, TagName, Value, returnVal);
}
</code>
I want to provide a function that will take variable parameters so I can build an attribute list for an XML tag. This function is the function I call with the variable parameters. When var_arg is called I get corrupted data.
Another question I had was, I saw CString Format uses a LPCTSTR variable where each parameter could be a different type, that is one parameter could be an int, another a double and another a string. Since I want the same to work here, is it proper to employ the same tactic or should I use COleVariant?
Thanks!
|
|
|
|
|
You need to have a way to tell the function how many parameters are in the ... part, and their types. Since you want to have any number and differing types, you will need something rather complex - copying the format string method used by CString::Format() wouldn't be the worst way to do it.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Laugh it up, fuzzball.
|
|
|
|
|
thanks for the info... quick question.. From where do I get the value of how long it is. Do I passs that myself or can that be determined programmically?
Thanks!
|
|
|
|
|
You can do it either way. CString::Format() infers the number of params from the number of %x inserts, but you can also pass the number as an explicit parameter.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
Hi,
I wrote a dll which contains classes using stl symbols (valarray).
First, this compiled well, but crashed at runtime. I then added to my code the following lines :
#ifdef EXP_STL
#define EXPIMP_TEMPLATE
#else
#define EXPIMP_TEMPLATE extern
#endif
EXPIMP_TEMPLATE template class EXP_STL std::valarray<double>;
Now, it doesn't compile, wiht error C2470 (sorry, but my error description is in French ...).
What happens ? What must I do to make it work ?
Thank you very very much.
|
|
|
|
|
Hi,
First of all, I'd try making sure that the executable and the DLL are built with exactly the same dynamic version of the run-time library. Hopefully this will solve your problem away. If it doesn't, please report back and we can think it over again.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, the executable and the dll were built at the same time.
But after hours spent on the net, I found a solution to my problem, which seems (not fully tested yet) to work with <vector>.
But the problem persists with <valarray>. To be more precise, I have an unresolved external link error which concerns the <slice_array> class. And here, I have no idea why...
Thanks.
|
|
|
|
|
Sorry fo my first answer. Some words were missing because I had problems with the HTML formats...
Ok, let's write it again. I said :
Yes, the executable and the dll were built at the same time.
But after hours spent on the net, I found a solution to my problem, which seems (not fully tested yet) to work with the class VECTOR.
But the problem persists with VALARRAY. To be more precise, I have an unresolved external link error which concerns the class SLICE_ARRAY. And here, I have no idea why...
Thanks.
Could you help ?
|
|
|
|
|
Hi,
I am using a CView to display a GDI+ image. My problem is when I change the image displayed i want to erase the background first. Invalidate(true) appears to have no effect, does anyone know why this is the case? Any clues at all would be appreciated!
Cheers
Rich
|
|
|
|
|
Hi,
first of all, sorry for posting on the VC++ board, but there is no networking board here, and due to the fact that I am using VC++ ... here I go:
I got a question on SOCKETs.
I have a SOCKET listening on a specified port.
When a client connects, I call accept. Due to specific reasons I do not call recv after this directly. There are about 1-2 seconds after the accept call until I loop on recv. Now my question: what happens with the data sent from the client to my SOCKET in the meanwhile? Is it lost? Is is buffered and I receive it when I then call recv?
Thanks a lot!
Chris
|
|
|
|