In the C ++ class, vector declaration, error "Expected Parameter Declarator"

tags: c++  

In the C ++ class, declare the Vector in the following method, will report an error: "Expected Parameter Declarator".

class A{
private:
    Vector <int> AUX (5); // you want to apply for a Vector of 5
};

The error reason is that the compiler cannot distinguish whether the statement is a member variable declaration or a member function declaration.
solution is to eliminate ambiguity.
has the following three methods:

  1. Initialize using constructor list
class A{
private:
    vector<int> aux;
public:
         A (): AUX (5) {} // Use the list initialization, initialize AUX to the length of 5
};
  1. Initialize using {}
    {} Initialization is also known as universal initialization, which can be used anywhere, with consistent semantics.
class A{
private:
    vector<int> aux{0,0,0,0,0};
};
  1. Use the Vector's assignment constructor
class A{
private:
    vector<int> aux = vector<int> (5, 0);
};

Intelligent Recommendation

&quot;reference

Reference is a new language feature introduced by C++. It is one of the important contents commonly used in C++. Correct and flexible use of references can make the program simple and efficient. I fou...

Input.GetAxis(&amp;quot;&amp;quot;) Input.GetAxisRaw(&amp;quot;&amp;quot;)

Input.GetAxis Get axis static function GetAxis (axisName : string) : float Descriptiondescription Returns the value of the virtual axis identified by axisName. Returns the value in the ...

Bean quot

Bean's reference statement First of all, this series of blog refers to the oil pipeSpring Expression LanguageTeaching videoReferencing BeansAnd write. start This episode is a simple look at how to use...

Exception in thread &amp;amp;quot;main&amp;amp;quot; error when deploying web project

The main reason: the JDK version used by the container does not match For example, tomcat7 does not support JDK5, which is a fundamental problem. Solution: Use the matching JDK according to the corres...

More Recommendation

An internal error occurred during: &amp;quot;Updating Struts 2 Model&amp;quot;.

Struts.xml filexml formatturn on. window-General-Editors-File Associations find the * .xml, and then select the following MyEclipse XML Editor - default...

Error in mounted hook: &amp;quot;TypeError: Cannot set property 'bottom' of undefined&amp;quot;

The template in the parent component music-list.vue calls the child component scroll Set the bottom value of the root element of the child component in a method in the methods of the parent component ...

C ++ Compile Error: Declaration of Anonymous Class Must Be a Definition

wrong reason I want to declare an anonymous class, but there is no type of structure. For example, if there is a code below, there will be such an error. Commonly causing the mistake of this problem W...

【TypeScript】Declaration expected error (TypeScript)

1. Question: TypeScript error on the mobile app terminal, Declaration expected; 2. Source code: 3. Screenshot: 4. Summary: Typescript will not report errors and report very specific, just saying Decal...

[C ++ Daily Learning Notes] Internal class+Youyuan, Statement Class (Foreer Declaration Forward Declaration), single parameter constructor hidden type conversion

1. Single parameter constructor in the class, constructor hidden type conversion AbovemainInitialization objectaThe way; the conventional initialization isAA a(10), The writing of the writing type her...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top