Compiler doesn't recognize push front

Hi guys,
New class is a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <list>

class OtherClass{
   int something; 
   string somethingelse; 
}

 class NewClass{
      list<OtherClass> List;
public: 
      NewClass(){ return list<OtherClass> List} //C'tor
}

int main(){ //I do not return any value so 'int main()' is pointless here
	NewClass test=NewClass("New"); //C'tor
	test.push_front (p1); //p1 is already declared and allocated //ERROR
}


The error I get is:
error C2039: 'push_front' : is not a member of 'NewClass', but this is STL list's method and I have included it. Will be glad to get some help.

Cheers.
Last edited on
closed account (z05DSL3A)
You are missing quite a bit of information for anyone to be able to help you.

What is NewClass, where is it defined how is it implemented what is p1 and so on.


PS. it should be int main not void main.
First of all it is unknown what is NewClass, where was it defined? Does this user-defined type have method push_front?
Edited the code, I hope it is clearer now.
What is it

NewClass test=NewClass("New");

???

Class NewClass has no a constructor that accepts an argument.
Last edited on
You have two problems:

1) Constructors don't return anything, they construct the object. I'm not sure you understand how functions work anyway. Go read up some on them.
2) Your class doesn't have a push_front method, so the compiler complains. Just because you have a list in there doesn't mean you can magically expect it to know you mean to push_front in that list.
Sorry for being confusing, updated once again.
@IrarI
void main(){ //I do not return any value so 'int main()' is pointless here


Whether you return a value or not but according to the C/C++ standards function main shall have return type int. So this definition

void main()

is simply invalid.
@IrarI


It seems that you do not understand what you are written by others. One more this statement

NewClass test=NewClass("New"); //C'tor

is invalid. Class NewClass has no constructor with a parameter.
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <list>

class OtherClass
{
public:
   int something; 
   std::string somethingelse; 
};

class NewClass
{
public: 
      NewClass()
      {
      }

      void Add(OtherClass value)
      {
          list.push_front(value);
      }

private:
    std::list<OtherClass> list;
};

int main()
{
    NewClass test;
    OtherClass oc;
    test.Add(oc);
}
NB:Not intended to be a definitive example. Just trying to clarify what I think you are trying to do.

See the site tutorial for more info on classes:
http://www.cplusplus.com/doc/tutorial/classes/
Topic archived. No new replies allowed.