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 am trying to create a code using vectors and other c++11 utilities. The above mentioned(on the title) error occurs in my code and despite I looked for a solution to this error on the internet I did not find something that works into my code. I tried to make some type castings but did not work. I present you the contentious part of code below:
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <algorithm>
#include <list>
//#include <Winbase.h>
using namespace std;
// A struct describing a product.
typedef struct Products
{
string category;
string name;
float price;
} Product;
inline void scenario1(int num_cashiers)
{
vector<Product> products; // It is a vector(a pseudo-second dimension) of products which will be used for each customer
vector<vector<Product>> customers; // A vector containing all customers
vector<vector<vector<Product>>> cashiers(num_cashiers); // A vector describing the supermarket cashiers declaring a queue of customers for each cashier
double start = GetTickCount(); // It will be used for counting 10 secs until next update
vector<int> total_products(num_cashiers); // A vector keeping the total number of products of each queue
list<string> categories; // A list containing all the categories of the products
list<float> categories_prices(categories.unique().size()); // A list containing all category prices
//THE ABOVE LINE - THE LAST ONE IN THIS PART OF CODE - IS THE LINE I GET THE ERROR!!!
....
}
What is wrong with the code?
Thank you everyone in advance!
list::unique is a void function, it does not return anything. On that last line, where you call categories.unique().size(), you are calling .size() on a void expression.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
for a homework i have to create a vector of objects who have some attributes, included an ip adress, and order the vector according to their IP adress. I'm having some trouble creating the vector, heres the code.
#include <iostream>
#include <fstream>
#include <string>
#include <string>
#include <algorithm>
#include <vector>
#include "data.h"
using namespace std;
void createVect(ifstream inFile) {
string month, day, ip1, ip2, ip3, ip4, temp, ip;
string t1;
int i = 0;
size_t n = 3;
vector<data> vect;
}
but im getting an error when trying to define the vector: "data" is ambiguousC/C++(266).
The code is bigger but this is the only relevent part (I think).
class data{
public:
std::string mes;
int dia;
std::string hora;
int ip;
data();
};
It's a pretty simple class, i just need it to store the data from the file i'm using.
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 know there's a lot of different threads with this similar issue but I've gone through a number of them and have fixed any of the possible issues that may be resulting in this error but I keep getting it.
I'm trying to test some of functions in my class file but whenever I try calling them I get that error.
Here's one for example.
main.cpp
#include <iostream>
#include <vector>
#include "Graph.h"
using namespace std;
int main(){
Graph graph;
newState();
return 0;
}
Graph.h (I know I shouldn't be using namespace here but I'm still doing it for now)
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
class Graph{
public:
Graph();
Graph(vector<Edge> const &edges, int N);
void printGraph(Graph const &graph, int N);
// print adjacency list representation of graph
void createTree(GraphNode *root, int state[]);
void newState();
private:
int states = 8;
int initialState[8];
int nextState[8];
};
Graph.cpp
#include "Graph.h"
void Graph::newState(){
srand (time(NULL));
int random = rand() % 4 + 1;
cout << random;
};
I feel like I'm trying to do the bare minimum but it just does not want to work. Can anyone please tell me where I'm going wrong?
newState is not a free-standing function. It is a non-static member function of Graph class. Which means, it must be called on an instance of Graph. What you probably meant to do is:
Graph graph;
graph.newState();
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 have the following code excerpt.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <string>
#include <array>
using namespace std;
int solver(int T)
{
/* read IA */
ifstream inputFile("IA [0;1.3077].txt");
vector<int> ia;
if (inputFile) {
int num;
while ( inputFile >> num) {
ia.push_back(num);
}
}
}
int main (void) {
solver(360);
}
But it gives me this error:
error: implicit instantiation of undefined template
'std::__1::vector<int, std::__1::allocator<int> >'
vector<int> ia;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:200:29: note:
template is declared here
class _LIBCPP_TYPE_VIS_ONLY vector;
The goal is to read a txt file with integers per line without knowing how many lines there are in advance. I'm choosing a vector to hold the data because I don't want to initialize an integer array with a fixed size. Does anybody have any suggestions?
Also, I understand that the variable T is unused - I will use it after the .txt file is loaded.
You need to:
#include <vector>
You must alway include directly all the headers for the types you use.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have data.h:
#ifndef DATA_H_INCLUDED
#define DATA_H_INCLUDED
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class student{
public:
string id;
int points [6] = {0,0,0,0,0,0};
};
#endif // DATA_H_INCLUDED
And I have enor.h:
#ifndef ENOR_H_INCLUDED
#define ENOR_H_INCLUDED
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
#include "data.h"
using namespace std;
enum status{norm,abnorm};
class enor{
public:
/*some voids*/
Student Current() const { return elem; }
student elem;
private:
/*some voids*/
};
#endif // ENOR_H_INCLUDED
And I got 'Student' does not a name a type, but why? I tried also if the Student calss is in enor.h, but also this error. how can I resolve this, and why is this?
You have a difference in your case for your student class:
class student - Lower case s
Student Current() const - Upper case S
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
I am trying to insert pair values < float,string > into my map class
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <set>
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<float,string> output;
output.insert(pair<float,string> ( 200.5, "foo" ));
output.insert(pair<float,string> ( 100.5, "batr" ));
map<float,string>::iterator mps1;
map<float,string>::iterator mps2;
mps1 = output.begin();
mps2 = output.end();
while (mps1 != mps2)
{
cout<<mps2->first
<<" "
<<mps2->second; //crashes here
mps1++;
}
system("PAUSE");
}
Using the debugger , it crashes when it does to the following line
<<mps2->second;
Can someone explain to me , thanks
You're supposed to access mps1, not mps2.
mps1 is the iterator you're incrementing for use; mps2 is the "end iterator" which you must not dereference.
It's a pretty basic typo / logic error.