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

  • Thread starter Thread starter axed
  • Start date Start date
  • Tags Tags
    Error Type
Click For Summary
SUMMARY

The forum discussion centers on a C++ compilation error related to object instantiation. The error occurs when attempting to assign a pointer of type `PriceFeed*` to a variable of type `PriceFeed`. The correct instantiation should utilize the stack allocation instead of heap allocation. The line causing the error is `PriceFeed pf = new PriceFeed(tickers);`, which should be replaced with `PriceFeed pf(tickers);` to resolve the issue.

PREREQUISITES
  • Understanding of C++ object-oriented programming
  • Familiarity with pointers and memory management in C++
  • Knowledge of C++ constructors and initialization
  • Basic experience with the Standard Template Library (STL) in C++
NEXT STEPS
  • Review C++ memory management concepts, focusing on stack vs. heap allocation
  • Learn about C++ constructors and how to properly initialize objects
  • Study the use of vectors in C++ and their initialization
  • Explore common C++ compilation errors and their resolutions
USEFUL FOR

C++ developers, software engineers, and students learning object-oriented programming who are encountering issues with object instantiation and memory management.

axed
Messages
2
Reaction score
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
new returns pointer.
 
thanks a lot.
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 70 ·
3
Replies
70
Views
5K
Replies
6
Views
2K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 65 ·
3
Replies
65
Views
8K
  • · Replies 57 ·
2
Replies
57
Views
5K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K