Copy control for pointers in string [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I have this test and while studying I came up with the following question that I don't even understand (nor the question or the answer)
I know coding, I just don't understand all the nonsense they try to teach us.
So the question is:
Q: The class string has pointers to an array of char. Which of the three copy control solutions for pointers, does the class must define?
A: value_like semantics
I do know that string is an array of chars, but I don't know what are "copy control solutions", I'm not even sure what is copy control (copy constructor maybe??) and what is value_like semantics??
Hope the question makes sense, it was translated from Hebrew.
Thanks for your help :)

"Copy control solutions" probably refers to implementation strategies for copy constructor and copy assignment. I would assume that your textbooks at some point list the three solutions for pointers, given the peculiarly specific wording of the question.
Therefore, look them up and understand what they are about. Knowing how to implement copying for resource-managing objects is one of the most essential language-specific skills for a C++ programmer.

Related

C++ operator overloading for embedded DSL language in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to use C++ operator overloading and create a DSL-like syntax for embedded DsL code in c++.
"a": auto = call("add2Numbers", "b", "c");
This is what I would like ideally. But anything close to this as valid C++ would be acceptable.
Good advice: don't. C++ is a big multi purpose language and already complicated enough. You will confuse people (and yourself too!) if you randomly change stuff. Especially operator overloading and the proposed pre processor should be treated carefully.
My advice for you is to write the functions you need. You gave an example about some kind of assignment (sorry, don't understand the given code) and I'm sure it is perfectly possible to write a function with a convenient interface to achieve what you're trying to do. The advantage is that your synthax stays all C++ and possible readers (and again your future self) don't get confused.
I hope I understood your question properly. If not, please correct me.
Felix

When is using an iterator appropriate? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm currently taking a class on data structures (in c++) and today we briefly touched iterators. The prof didn't really make much sense of it and while i acquired a basic understanding of what iterators do I was wondering if someone could expand on the topic, possibly giving a Pro's/Con's list of using them vs not preferably in c++ but a general outline would also work.
Thanks in advance to everyone who responds :).
Using an iterator can maintain the protected status of object data. For example, you will probably be iterating through a list. An iterator returned could allow you to step through the list elements (nodes) without being able to directly modify the list. It's implementation dependent, though. You could easily write your own iterator that allows direct modification of the list vectors. It's just another form of convenience abstraction.
An iterator as an interface (pure abstract) could be used to provide a common interface to iterate through different types of lists or arrays, as they are in Java, C#, etc.

A property which is not true for classes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am facing the question in below (especially C++)
A property which is not true for classes is that they
(A) are removed from memory when not in use.
(B) permit data to be hidden from other classes.
(C) bring together all aspects of an entity in one place.
(D) Can closely model objects in the real world.
Could anyone explain me about meaning of that question?
What is property for classes?
I am new in C++, so if this question is posted anywhere, kindly inform me.
Thank you!
In order: No. Yes. Maybe. Hopefully.
Could anyone explain me about meaning of that question?
The question gives four "properties" (or traits) of things:
a) are removed from memory when not in use.
b) permit data to be hidden from other classes.
c) bring together all aspects of an entity in one place.
d) can closely model objects in the real world.
Your task is to identify at least one of those four choices which does not apply to the programming concept called a class.
This question is asking about (not necessarily in this order):
Real-world modeling
Garbage collection
Encapsulation
Interfaces

Adding multiple data types to the same variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am relatively new to programming, and I can only really understand C++. I have recently started working on a project that requires the user to input something that will allow them to make a selection. I can't figure out how to make it possible for the user to input a string or a char but get the same result. I know that this would require that I assign the variable that the user inputs (for example 'a') two data types, but how do I do that? I've tried using "string/char a;" but that doesn't work.
Could someone please help me with multi-data-type variables?
Thanks
The string type will work for all user input. Since it "doesn't work" for you, we can't help you further if you don't show us what you tried.
If the User is the one making the Input from the I/O, then you get to decide if you will treat the input as a string or char. After receiving the Input you should know what you want to do with it. And you can also store the input data in array, vectors or list. Primitive data types can do so many things just understand the purpose and function of your program.

Is there a "generics-like" feature in C++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to create a list class in C++ similar to the lists in Java. Is there a way I can have it be able to list whatever object it wants to? The class resizes arrays to create the list, but what I need to do is find out the kind of object that's needed to store.
Yes, C++ has templates that can be used to create generic containers roughly similar to Java generic containers.
While your immediate reaction might be to assume that std::list is similar to a Java list, that would be a mistake. In Java, a list basically just means a sequence. In C++, a std::list is a linked list (which is rarely useful). Most of the time you want to use an std::vector (which is more like Java's ArrayList).
Yes, there is, and it's called Templates