Error: conversion from `PriceFeed*' to non-scalar type `PriceFeed' requested

In summary, the error "conversion from `PriceFeed*' to non-scalar type `PriceFeed' requested" means that there is an attempt to convert a pointer to an object of type PriceFeed to a non-scalar type PriceFeed, which is not allowed. This error can occur when trying to assign a pointer to an object of type PriceFeed to a variable of type PriceFeed, due to pointers and objects being different types. To fix this error, the pointer must be dereferenced before assigning it to the variable, or a different type that is compatible with pointers can be used. This error can also be caused by other factors, such as attempting to convert a pointer to a non-pointer type or between incompatible types. This error
  • #1
axed
2
0
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;

class PriceFeed
{
public:
PriceFeed(vector<string>& tickers)
{
// init(tickers);
}
}
int main ()
{
vector<string> tickers;
tickers.push_back("AAPL");
tickers.push_back("XOM");

//PriceFeed(tickers);
PriceFeed pf = new PriceFeed(tickers); // Error on this line
system("pause");
//return 0;
}

Can you please tell me where am i going wrong. This is the error
conversion from `PriceFeed*' to non-scalar type `PriceFeed' requested
 
Technology news on Phys.org
  • #2
new returns pointer.
 
  • #3
thanks a lot.
 

Question 1: What does the error "conversion from `PriceFeed*' to non-scalar type `PriceFeed' requested" mean?

The error means that there is an attempt to convert a pointer to an object of type PriceFeed to a non-scalar type PriceFeed, which is not allowed.

Question 2: Why am I getting this error when trying to assign a pointer to an object of type PriceFeed to a variable of type PriceFeed?

This error occurs because pointers and objects are different types and cannot be directly assigned to each other. The pointer must be dereferenced to access the object it is pointing to.

Question 3: How can I fix this error?

The error can be fixed by dereferencing the pointer before assigning it to the variable of type PriceFeed, or by using a different type that is compatible with pointers, such as a reference.

Question 4: Can this error be caused by other factors?

Yes, this error can also be caused by attempting to convert a pointer to a non-pointer type, or by attempting to convert between incompatible types.

Question 5: Is there a specific scenario where this error is commonly encountered?

This error is commonly encountered when working with pointers and objects in object-oriented programming languages such as C++ or Java. It can also occur when using APIs or libraries that require specific data types for input or output.

Similar threads

  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
885
  • Programming and Computer Science
3
Replies
70
Views
3K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
2
Replies
65
Views
5K
  • Programming and Computer Science
2
Replies
57
Views
3K
  • Programming and Computer Science
Replies
1
Views
871
  • Programming and Computer Science
Replies
13
Views
1K
Back
Top