Tuesday, 15 July 2014

c++ - Can't set value of static object field (error LNK2001: unresolved external symbol) -


I think I am writing a simplified version of the problem in a game. I am trying to set a stable field in my class from one of my main methods to another class. Although this code will not exist and I do not understand why

I get an error

1> source.obj: Error LNK2001: unresolved external symbol "Public: Static Class A * b :: A "(? A @ b @@ 2PAVA @@a)

  class A {public: A () {}}; Class B {Public: Fixed A * A; }; Int main () {B :: a = new A; }  

What is the rule saying that I want to define my static class member outside the class to make this link?

with your comment

But what does this rule define?

It is called

Definitions and ODR

Definitions are announcements that are fully defined by the entity presented by the declaration Does. Each announcement is a definition, except for the following:
... 4) Declaration of a stable data member within class definition

  struct S N; // defines S: n constant i int; // declares, but S: i} does not define; Int S: i = 0; // defines and starts S: I  

as an additional reference you can also check here

Update: < / Strong>
Finally available for the present (June 2, 2014) (currently a copy of the current issue of $ 30 $ I think):

§ 9.4.2 < / H3>

2 The declaration of a stable data member is not a definition in its Class D fission, and it is an incomplete type other than the CV-validation zero. The issuer. For the static data subscriber, the salvage will appear in the namespace area in the category of member class. When the namespace is installed in the area, the name of the static data member will be qualified using the client name: :: operator. The initial expression in relation to a static data member is within its square


No comments:

Post a Comment