|
MOTLEY !!!!
Sorry. First of all, you're asking in the C++/CLI board, which is for managed C++. Yeah, the new name makes it less clear.
Secondly, you should prefer to use the std::string class, or even CString, rather than manipulating char *.
Finally, the first argument passed into strcat should contain enough space after the null terminator to make room to copy in the second string. This is the sort of crap that makes C string handling really sucky, compared to using std::string.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
char *t1="Tommy";
char *t2="Lee";
strcat(t1,t2);
//wrong
char t1[]="Tommy";
char t2[]="Lee";
strcat(t1,t2);
//right
char*'s are pointers to an array of char's
|
|
|
|
|
Hi all,
When Iam making a "push_back" into the vector,Its pushing back a new object into my vector(co's it goes to the constructor of the object) although ,Iam passing a refererence of the object into the "push_back".
Does "Push_Back" make a copy of the object passed to it.How can I avoid it....
Thanks...
|
|
|
|
|
Yeap push back will make a copy. It does not matter you pass a ref into it. You should have found that a lot of copy constructors take a reference and that's what you r doing.
To avoid it, you should declare a vector of pointers rather than the that class.
e.g.
class CMyClass
{
....
};
std::vector<*CMyClass> myVec;
Just remember to delete everyting at an appropriate time so that there's no memory leak
|
|
|
|
|
Laffis wrote:
Yeap push back will make a copy. It does not matter you pass a ref into it.
no, it get what you give to it, a ref, a pointer or a value, but nowhere push_back() take the decision of copying its parameter to add to the vector.
Laffis wrote:
You should have found that a lot of copy constructors take a reference and that's what you r doing.
but it's their job ! constructors are supposed to create a new instance of a class, getting some or some other parameter types. of course, a constructor getting a reference have to copy/clone its parameter to avoid multiple references on the same memory area...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
push_back should make a copy toxcct, it being a copy of the object, or a copy of a pointer or whatever you declare it should be.
Consider the following test code:
class CMy
{
public:
CMy(const CMy &m)
{
this->n = m.n;
};
CMy(const CMy *pm)
{
this->n = pm->n;
};
operator=(const CMy &m)
{
this->n = m.n;
};
CMy() {n=911;};
int n;
};
void main(...)
{
std::vector<cmy> vt;
CMy *my1 = new CMy();
vt.push_back(*my1); // made a copy here?
delete my1; // delete the created CMy object.
std::vector<cmy>::iterator it = vt.begin(); // LineA,crash?
CMy my2 = *it; // LineB,crash?
int nn = my2.n; // But you still get 911 here!
}
If push_back does not make a new copy, LineA and LineB will crash.
But on the contrary, you should see that at the last line the object still exists in the vector.
It is not their decision to implement copy constructor. You should make your copy constructor when shallow copying is not enough, otherwide do not making your own. The decision is yours.
In the above test code the copy constructors are not neccesary at all. I had the impression that the msg author has debugged into copy constructor so I assumed he wrote his own version.
|
|
|
|
|
Yes,I did Overrided my copy Constructor,co's wanted deep copying.Now Iam storing in my Vector- Pointers & not objects anymore....
|
|
|
|
|
Just becareful with memory leak and you are rolling.
As far as I know, list, map also make copy of inserted element.
|
|
|
|
|
hi
i wanna know how to turn on/off the lights with a C code.
would u tell me what hardawre i do need to do this and also tell me how to write the code?
thx
|
|
|
|
|
did you really google for that before posting your request ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
i don know to search for what.
i don know anything about these subjects.
would u tell me an introduction about it and what to search for and i will look for them myseelf.
thx so much
|
|
|
|
|
i'd like to help you more, but still i don't know what you're looking with more precision, i can't...
are you yust looking for programming help, or you are asked to design the electrical/electronic part of that system ?
do you use a PIC or so to code this in C ? (and is it necessarily in C ?)
you'll have to provide more infos if you want some consequent help, otherwise the best you'll get will be people asking for what you want, the worst being insults...
any help so ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
hi toxcct
u know i am a complete idiot in these subjects.
i don know wether i can program such a thing with C.
but would u say if i want to do such a thing, how should i and what should i do? and what hardwares do i need.
or i need an elect kit?
|
|
|
|
|
you don't really answer my questions...
please do it if you want me to help you more efficiently.
moreover, i have some more for you :
what lights do you want to act on ? small LEDs, or big ones abstrated behind an automaton ?
is there even something started designed on this, or you start the whole job ?
do you do this for you or were you asked to ?
hamidreza_buddy wrote:
u know i am a complete idiot in these subjects.
i never said that... i'm just trying to help you...
hamidreza_buddy wrote:
i don know wether i can program such a thing with C.
most industrial things like this one can be done in C...
please answer my question to help me understand my you want...
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
>>is there even something started designed on this, or you
>>start the whole job ?
i am gonna start it . i don know anything abt it.
>>do you do this for you or were you asked to ?
no i just want to do it for myself
i mean these simple light bulbs not a LED.
|
|
|
|
|
well, your thread contains an hardware question (which should have been asked into the Hardware forum[^]).
for what you look for programming, you should first learn at PICs and PALs integrated circuits, because your code cill depend a bit on which you code for... moreover, it will also depend on how you consider turn the light on/off (distant interruptor, radio connection, special condition from within the embedded code, etc...).
sorry but i can't help you more until you don't tell me how is designed (or at least, how you imagined as designed) you project (HW + SW + linkage b/w them)
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
you need to get power supply from the Electricily Dept..;P
V
|
|
|
|
|
Hi I have not really tried extensively and I only saw one instance so far but have forgotten what happened...
What may happen if a multi-threaded executable calls a single-threaded DLL? This is not thread safe. What can one do to make it threadsafe--if the 3rd party vender refuses to provide a multi-threaded version of the dll unless you increase the money?..
|
|
|
|
|
Hi, I've got a ListBox and I want to know the max number of characters, that can be added in a single line. I need this because there is an info that exceed in characters the width of the ListBox. What I'm thinking is get the max number of characters and cut the info in several lines.
Any idea?
Tnx
|
|
|
|
|
|
?? And the max characters that can be written in a single line?
|
|
|
|
|
ok, maybe I'm stupid, but it seems to me that after I called one constructor and the program returns it automatically calls another overloaded constructor.... why can this happen? I will check the program again tomorrow and try to describe the problem a bit closer and maybe provide some code, but just in case anyone has an idea I post this tonight.... drives me crazy right now... thanks!
Johanna
|
|
|
|
|
|
I am on a project that reads in assembler language from a file and then prints if out. here is an example.
input:
ADD 4,2,1
TEST
JMP 3
BR 14
ADD 3,7,9
the output should look like this:
Op code: ADD
Params: 4
Params: 2
Params: 1
Opcode: TEST
No Params.
Opcode: JMP
Params: 3
ect......
Here is what my code looks like:
int main()
{
string theLine;
string op;
string p;
ifstream infile;
infile.open("assembler.txt");
int line=0;
while(getline(infile,theLine))
{
cout<
|
|
|
|
|
You will have to parse the string that has the commas. Consider the line of code in your example:
cout << "Paramers:" << p << endl;
As it is now, p will point to the string "4,2,1" for example. You should test p at this point for commas, perhaps in a loop, parse and tokenize each number between commas, and print the result (each parameter).
-- modified at 16:27 Wednesday 14th September, 2005
|
|
|
|