operator « const « C Q&A

Home
C Q&A
1.assembly
2.buffer
3.Card
4.Cast
5.compile
6.console
7.const
8.constructor
9.database
10.Date
11.Debug
12.Design
13.Development
14.DLL
15.encrypt
16.enum
17.eof
18.Event
19.fork
20.Format
21.gcc
22.gdb
23.graph
24.graphics
25.gui
26.Holiday Event
27.image
28.IP
29.iterator
30.macro
31.makefile
32.malloc
33.Menu
34.mysql
35.network
36.openssl
37.operator
38.password
39.pipe
40.preprocessor
41.printf
42.pthread
43.Regular expression
44.scanf
45.semaphore
46.SerialPort
47.server
48.Socket
49.sql
50.SQLserver
51.sscanf
52.std
53.stdin
54.stdout
55.stl
56.strcmp
57.stream
58.switch
59.Template
60.thread
61.timer
62.unix
63.video
64.Virtual
65.visualstudio
66.winapi
67.windows
68.xml
C Q&A » const » operator 

1. const MyClass& operator= ... ...    bytes.com

nembo kid wrote: Was wondering why the function that overloads = operator, returns always a const reference to the class. > Why the qualifier 'const'? First of all, the premise is untrue. The compiler-provided operator= does not return the reference to a const object. It returns a reference to a non-const object. Second, if one of _your_ classes returns a reference ...

2. What is the usage of "valarray operator+() const;"?    bytes.com

john Hi, in TC++PL3 on page 665, regarding valarray member functions, it is mentioned: "valarray operator-() const; // result[i]= -v[i] for every element // similarly: +, ~, !" I checked the web and could not find anything that explains the need of this "operator+". Any ideas? In MSDN it is mentioned: "Standard C++ Library Reference valarray::operator+ A unary operator that applies ...

3. operator= for a class with a const reference member    bytes.com

I have a class that has a member that is a const reference: class MyClass { public: MyClass(const AnotherClass& ac); MyClass(const MyClass& mc); MyClass& operator= (const MyClass& mc); private: const AnotherClass &m_ref ; }; How do I implement the assignment "constructor"? MyClass& MyClass::operator= (const MyClass& mc) { m_ref = mc.m_ref ; //dosen't compile (obviously) m_ref(mc.m_ref) ; //dosen't compile (obviously) }

4. Derived::Derived(const Base&) and Derived& operator=(const Base&)    bytes.com

Hi folks, Can somebodyshed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public: virtual method() = 0; } class Impl1: public Interface { public: Impl() { ... } Impl(const Interface&); // problem 1 virtual ~Impl() { ... } Impl& operator=(const Interface&); // problem 2 virtual method() { ... } } The problem ...

5. Operator= and const members    forums.devshed.com

Don't make the variable const? I can't see any reason why you would want or need to make it const, yet still want or need to assign to it later in the program. If it's assigned once and only once, make it const. If it needs to be assigned again at any point in the program, don't.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.