473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

arrays through pointer representation issue

momotaro
357 100+
I have a class called vetor which the is the following:
Expand|Select|Wrap|Line Numbers
  1. class Vector
  2. {
  3.  
  4. private:
  5.     Vector* v;
  6.     int length;
  7.  
  8. public:
  9.     DynamicVector(double* v=0, int length=0);
  10.     ~DynamicVector(void);
  11.     void remplissage();
  12.     void affiche();
  13.  
  14. };
Expand|Select|Wrap|Line Numbers
  1. #include "StdAfx.h"
  2. #include "DynamicVector.h"
  3.  
  4.  
  5. DynamicVector::DynamicVector(double* v, int n)
  6. {
  7.     v = new double[n];
  8.  
  9.     for(int i = 0; i < n; i++)
  10.         *(v+i) = 0;
  11. }
  12.  
  13.  
  14. DynamicVector::~DynamicVector(void)
  15. {
  16.     delete []this;
  17. }
  18.  
  19.  
  20.  
  21. void DynamicVector::affiche()
  22. {
  23.     for(int i = 0; i < this->length; i++)
  24.         cout<< this->v+i <<endl; // does not print
  25. }
am expecting the function affiche to display the array but instead I get nothing!

please advise
thx in advance
Apr 4 '11 #1
1 1182
hype261
207 100+
Does this code even compile. I would seriously doubt it.
Expand|Select|Wrap|Line Numbers
  1.  
  2. class Vector 
  3.  
  4. private: 
  5.     Vector* v; 
  6.     int length; 
  7.  
  8. public: 
  9.     DynamicVector(double* v=0, int length=0); 
  10.     ~DynamicVector(void); 
  11.     void remplissage(); 
  12.     void affiche(); 
  13.  
  14. };
  15.  
Your class is called Vector, but you have a constructor and destructor named DynamicVector.

Where are you assigning a value to the Vector v???? Your
constructor doesn't assign a value to the Vector it assigns a value to the double v.

Expand|Select|Wrap|Line Numbers
  1.  
  2. DynamicVector::~DynamicVector(void) 
  3.     delete []this; 
  4. }
  5.  
  6.  
This is wrong also. I believe you want to use this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. DynamicVector::~DynamicVector(void) 
  3.     delete[] v; 
  4. }
  5.  
  6.  
Apr 4 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Mantorok Redgormor | last post by:
I always see posts that involve the representation of integers, where some poster claims that the unerlyding representation of an integer doesn't have to reflect on the actual integer, for example:...
12
by: junky_fellow | last post by:
How can I declare a function that returns a pointer to one dimensional array ?
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
23
by: Zach | last post by:
Is there any difference between: char *pointer; char* pointer; Is the choice one of aesthetics or does this denote real differences? Zach
15
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer...
43
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
2
by: abarun22 | last post by:
Hi I am new to SWIG and python. I have a problem while trying to call a C function from Python using SWIG as an interface. The function is defined as follows. void* myfunc(TfichierDLR *fichier,...
7
momotaro
by: momotaro | last post by:
I have a piece of code that is supposed to fill a 2D array and print it out using pointers, the problem in stead I get only a part of it correct! here is the code: #include <stdio.h> #define...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.