-4

I am working with Chromium Embedded Framework. I put the following in the main function.

CefRefPtr<CefRequest> cef;

CefRequest::ReferrerPolicy origin = origin;

cef->SetReferrer("www.google.com",origin );

During the make process I receive the following errors:

 error: ‘origin’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  cef->SetReferrer("www.google.com",origin );

                                            ^

the method:

virtual void SetReferrer(const CefString& referrer_url, ReferrerPolicy policy) =0;

Why is origin not being initialized and how can I initialize it?

Thanks

user3202058
  • 31
  • 1
  • 8
  • You're dereferencing an uninitialized pointer. You mean `CatRequest` is abstract? – LogicStuff Jul 03 '16 at 20:04
  • 2
    If you don't know why use of uninitialized variables is a problem, you should spend time going through the fundamentals of C++ from a text book. Take a look at [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to get started. – R Sahu Jul 03 '16 at 20:15
  • Yes, LogicStuff, CefRequest is abstract. I thought virutal and abstract were the same in C++. How do I instantiate a method in my main from an abstract class? – user3202058 Jul 04 '16 at 16:41

1 Answers1

1

It is just like the error says, your variable 'a' is uninitialised when you use it. You have declared the variable, but you have not initialised it. Then in the next line you dereference the variable. This will typically cause your program to crash. Your compiler is trying to warn you of this.

  • Thank you. However, when I initialize it with new, such as: CefRequest *a = new CefRequest; I get an error because "cannot allocate an object of abstract type CefRequest." Using a pointer does not allow for initialization either: a->SetReferrer("www.google.com",origin ); It is a completely abstract class with all virtual methods: [link] http://magpcss.org/ceforum/apidocs3/projects/%28default%29/cef_request.h.html – user3202058 Jul 04 '16 at 15:52
  • I'm not familiar with the API you're using here, but an abstract class such as this is generally designed as a base class to be derived from - it shouldn't/can't be used directly. You will need to look at the documentation in more detail to see how you are supposed to create the object you need. There may be a factory class or something. I notice there is a static `Create()` function in this class. Calling that may return a sub-classed object you can use - just guessing here - you need to read the docs. – bennji_of_the_overflow Jul 04 '16 at 22:34