Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have a class 'node' which has two members data and *next. When I am accessing data using pointer then it is working fine whereas when i am accessing it using double pointer , it is throwing an error . Can anyone explain me why this is happening?
class node{
public:
int data;
node *next;
};
push(&a,8);
void push(node **p , int x){
*p->data = 11;
}
Why this p->data showing error:
request for member ‘data’ in ‘ p’, which is of pointer type ‘node*’
Because *p->data is *(p->data), not (*p)->data.
Read about operator precedence.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int* i = new int(75);
double* d = new double(3.14159);
printf("%d\n",*i);
printf("%d\n",*d);
}
In the above code i returns a value of 75 however, d returns 1.
I tried explicitly initializing it as
*d = 3.14159
But the value is still returned as 1.
Can anyone explain what I am doing wrong here?
Use this for printing.
cout<<*i;
cout<<*d
"%f" is the (or at least one) correct format for a double if you want to use printf for printing the value of the double in C++.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm working on a C++ implementation of a Binary Heap, but I'm having some issues getting started. Here's a snippet of my code:
class binaryHeap {
public:
// Constructor
binaryHeap(int _capacity)
{
// initializes the binary heap with a capacity, size, and space in memory
_size = 0;
_n = ceil(pow(2, log10(_capacity)/log10(2)));
_heap = new int[_n];
}
~binaryHeap(void)
{
delete[] _heap;
}
/* Omitted: insert, remove, size, capacity functions
Not necessary to the issue I'm having */
private:
int _size;
int _capacity;
int _n;
int *_heap;
};
In the main.cpp file, when I write the following line:
struct BinaryHeap heap(10);
I get the error: Variable has incomplete type 'struct BinaryHeap'. Any ideas what is causing this?
I think this is a typo problem. Your binary heap class is binaryHeap, while in your main function, you are saying struct BinaryHeap heap(10);, which in the compiler's POV is a completely different type.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am having issues passing a file through to a constructor
#include "WordList.h"
#include<iostream>
#include<fstream>
using namespace std;
WordList::WordList(ifstream& infile){}
-----
int main()
{
WordList w1("input.txt");
}
Here the error is showing:
No instance of constructor matches the argument list, the argument types are (const char[10])
How can pass a file through a constructor then.
ifstream strm ("input.text", ifstream::in) ;
WordList w1 (strm) ;
You could also define WordList's constructor to take istream & as the parameter to generalize the routine.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;