-2

I'm new to c++ so there are tons of things I don't know, that's why I would like to ask someone with more experience.

std::vector<CProp*> filter(const string &deptName, const string &city, const string &country)const {
        ...
}

I'm using std namespace, so the std:: should be redundant, but if I remove it, the compiler shows errors (first of which is This declaration has no storage class or type specifier?). Why is that? I never had to use it elsewhere in the class, so there shouldn't be any conflict also I'm using only std namespace.

#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <memory>
#include <vector>
#include <algorithm>
using namespace std;

class ClassName {
    public:
        ...
    private:
        vector<CProp*> vector;

        vector<CProp*> filter(const string &deptName, const string &city, const string &country)const {
            return nullptr;
        }
}
adsamcik
  • 1,265
  • 12
  • 14
  • 6
    We need full code. And do not do `using namespace std;` never ever. – SergeyA Apr 08 '16 at 15:21
  • That cannot be. If you have a `using namespace std` then the removal of `std::` has to work. And further what SergeyA says. – Chiel Apr 08 '16 at 15:21
  • 6
    Please post a [mcve]. – Baum mit Augen Apr 08 '16 at 15:22
  • is there another `vector` type defined? – kmdreko Apr 08 '16 at 15:22
  • It's 'small' school homework that has this in source file, it's also in a single file without header due to automate testing limitation, I was expecting comment like that, should've mentioned. – adsamcik Apr 08 '16 at 15:22
  • vector vector above it is fine, like that and no there is no vector type defined. Can't risk posting full code atm, hoped that what I wrote would be enough. – adsamcik Apr 08 '16 at 15:23
  • 1
    Just stop using `using namespace std;` and type the 5 extra characters. It isn't that much more and it is nice and explicit. also see: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-in-c-considered-bad-practice – NathanOliver Apr 08 '16 at 15:24
  • 3
    @adsamcik: Why would that prevent you from posting the code? – Nicol Bolas Apr 08 '16 at 15:24
  • please post the minimal amount of code to reproduce the problem – kmdreko Apr 08 '16 at 15:25
  • You could post the error message, but if the compiler reports a name conflict when you don't specify std::, then there is a name conflict. – Kenny Ostrom Apr 08 '16 at 15:26
  • Someone from my school could find the code and use part of it in his own work, we have serious penalties for that. @NathanOliver I read this question, but std is really the only namespace I use or need for this part. – adsamcik Apr 08 '16 at 15:26
  • @adsamcik thats madness if theres a correct answer theres a corretc answer – AngryDuck Apr 08 '16 at 15:30
  • 4
    @adsamcik That might be but why develop bad habits. If you get into the habit of not using it then soon you will not even mind and will save yourself some really weird compiler errors. One of the best is trying to create a class named `time` after you use `using namespace std;`. see [this](http://coliru.stacked-crooked.com/a/23872d070326a52b) example – NathanOliver Apr 08 '16 at 15:30
  • (`SomeFunctions()` needs a return type and a semicolon.) – Biffen Apr 08 '16 at 15:37
  • @NathanOliver Thats a really good point, thanks. I guess they assume we won't run into this or I dunno, because it's written in sample code. This is my second task so far, so I am still unaware of c++ habits even though I try to learn them asap. – adsamcik Apr 08 '16 at 15:37

3 Answers3

5

This defines a member named "vector" which conflicts with std::vector

private:
    vector<CProp*> vector;
Kenny Ostrom
  • 5,639
  • 2
  • 21
  • 30
0

string also requires std::. So you should have

std::vector<CProp*> filter(const std::string &deptName, const std::string &city, const std::string &country)const {
        ...
}

And I agree with all the commenters saying "Don't use using namespace std".

Logicrat
  • 4,438
  • 16
  • 22
0
  1. You didn't close your class declaration with a semicolon ;. That is confusing the compiler.

  2. You also need to write void SomeFunctions(); as that is confusing the compiler too. And don't forget to add a definition for that function otherwise the link stage of your build will fail.

You'll also need some way of running something. To do that you need a main function. Or is that the job of someone else?

Bathsheba
  • 231,907
  • 34
  • 361
  • 483