I would like to do something like the following
class TMyClass
{
......
}
TMyClass* mc1 = new TMyClass;
TMyClass* mc2 = new TMyClass;
TMyClass* mc3=mc1+mc2;
Where the addition mc1+mc2 would take the desired information from each
object, put them together , then store them mc3. I tried overloading the
operator+, but when I compile the mc3=mc1+mc2 line, the compiler complains
about invalid pointer addition.
Anyone have an ideas?
Thanks for any and all help. It is greatly appreciated.
Brian Dumas
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =----- 3 1354
Brian Dumas wrote: I would like to do something like the following
class TMyClass { ..... }
TMyClass* mc1 = new TMyClass; TMyClass* mc2 = new TMyClass; TMyClass* mc3=mc1+mc2;
mc1 and mc2 are pointers and it makes no sense to add two pointers ever.
You could try
TMyClass* mc3 = new TMyClass(*mc1+* mc2);
where you overload the + operator suitably and define a copy constructor
if needed.
Brian Dumas wrote: I would like to do something like the following
class TMyClass { ..... }
TMyClass* mc1 = new TMyClass; TMyClass* mc2 = new TMyClass; TMyClass* mc3=mc1+mc2;
Where the addition mc1+mc2 would take the desired information from each object, put them together , then store them mc3. I tried overloading the operator+, but when I compile the mc3=mc1+mc2 line, the compiler complains about invalid pointer addition.
Anyone have an ideas?
Thanks for any and all help. It is greatly appreciated. Brian Dumas
In your example above, all the variables are pointers to
the classes, not instances of the classes. The compiler
is correct, because you are telling it to add pointers
together.
I think you meant:
TMyClass * mc3 = new TMyClass; // create an instance for the result.
*mc3 = *mc1 + *mc2; // Add the instances, not the pointers.
BTW, there is no requirement for classes to start with a 'T'
or a 'C'. Feel free to be different.
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book
On Wed, 11 Feb 2004 11:30:09 -0800 in comp.lang.c++, "Brian Dumas"
<br***@kvdco.co m> was alleged to have written: operator+, but when I compile the mc3=mc1+mc2 line, the compiler complains about invalid pointer addition.
Right. Stop using pointers. Stop using "new".
Put down that Java book and step away from it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Geoff Biggs |
last post by:
Evening all,
I'm trying to add a new built-in number data type to Python with its own
syntax, so I'm working directly with the interpreter rather than
creating my own extension module (side note: I've appended something
extra to the version thing in the Makefile - I doubt this is relevant to
the problem but it's probably best you have all the info). The complex
data type is similar to what I'm trying to do so I've been following
that as...
|
by: Tommy Lang |
last post by:
I am working on this project and I need some help/pointers/comments to
get me started, I am stuck.
The program will be used to store information in an array while it is
running.
I need to store objects of my classes Person(superclass),
Student(inherit Person), Teacher(inherit Person) in that array.
The name will be the unique key. These classes are all working ok. I
want to be able to add, remove, find etc. objects.
To all of this, I...
|
by: JustSomeGuy |
last post by:
I have an stl list that grows to be too huge to maintain effectivly in
memory.
There are elements within the list that could be stored on disk until
accessed.
However I don't want to expose this to the application class.
How can I extent the stl list to write some elements to disk when they
are put in the list
and read them from disk when they are read from the list.
|
by: jm |
last post by:
I am trying to do something VERY simple. I want to use this:
http://www.codeproject.com/csharp/dotnetbandobjects.asp?msg=727553#xx714692xx
to point to a web page.
I cannot use process.start because it opens the webpage in the last
opened IE window, not the window which is currently active. So, I am
trying to use the Microsoft Internet Controls COM.
|
by: Pierre Barbier de Reuille |
last post by:
Please, note that I am entirely open for every points on this proposal
(which I do not dare yet to call PEP).
Abstract
========
This proposal suggests to add symbols into Python.
Symbols are objects whose representation within the code is more
important than their actual value. Two symbols needs only to be
| |
by: Tarun Mistry |
last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies
to both (apologies if it breaks some group rules).
I am making a web app in asp.net using c#. This is the first fully OO
application I will be making, also my first .NET application, so im looking
for any help and guidance.
Ok, my problems are todo with object and database abstraction, what should i
do.
|
by: lennon1 |
last post by:
Hi, I have already started learning .NET and I have a question. If I
want to do anything - Display Data, Navigate, Update - with database
(SQL Server) in Visual Studio 2005, do I have to use all this objects :
- DATASET
- sqlDataAdapter
- BindingSource
- sqlConnection
I usually write database applications in Delphi, but now I want to
learn Dot Net platform ant it's quite diffrent than programming
|
by: sorobor |
last post by:
dear sir ..
i am using cakephp freamwork ..By the way i m begener in php and javascript ..
My probs r bellow
I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ...
Pls inform me as early as possible ..
I am waiting for ur quick replay ...Here i attached the source code ....
<!DOCTYPE...
|
by: StevenChiasson |
last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller.
This is more or less, your standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
|
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= |
last post by:
I get the above error in some of the ASP.NET web applications on a
server, and I need some help figuring out how to deal with it.
This is a rather long post, and I hope I have enough details that
someone who bothers to read all of it have some pointers.
Note, I have posted the stack trace and the code exhibiting the problem
further down so if you want to start by reading that, search for +++
Also note that I am unable to reproduce...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |