Expected constructor, destructor, or type conversion before '.' token

This is a discussion on Expected constructor, destructor, or type conversion before '.' token within the C++ Programming forums, part of the General Programming Boards category; Can someone please help me understand why I keep getting the error "Expected constructor, destructor, or type conversion before '.' ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6

    Question Expected constructor, destructor, or type conversion before '.' token

    Can someone please help me understand why I keep getting the error "Expected constructor, destructor, or type conversion before '.' token"? I've seen many variants of this error on other posts but none really seem to help me. I've included the important code fragments below. Let me know if more is needed. Thank you.

    Code:
    Code:
    /*
     Begin NRldlmain.cpp
    */
    
    #include "nr3.h"
    #include "sparse.h"
    #include "NRldl.h"
    //#include "interiorv1-N3-M3-K1.h"
    
    int k=1;
    doubleX_act[3]= {0.000000,0.957167,0.000000,};
    int NV=3, N=NV;
    int NC=3, M=NC;
    NRsparseMatmy_A;
    my_A.nrows = M;     ** Error **
    my_A.ncols = N;     ** Error **
    my_A.nvals = M*N;   ** Error **
    
    /*
     Begin sparse.h
    */
    
    structNRsparseMat//sparse matrix data structure for compressed column storage
    {
    Int nrows;                            //number of rows
    Int ncols;                            //number of columns
    Int nvals;                            //maximum number of nonzeros
    VecInt col_ptr;                            //pointers to start of columns. length is ncols+1
    VecInt row_ind;                            //row indices of nonzeros
    VecDoub val;                            //array of nonzero values
    
    
        NRsparseMat();                            //default constructor
        NRsparseMat(Int m,Int n,Int nnvals);                //constructor. initializes vector to zero
    VecDoub ax(constVecDoub &x) const;                //multiply A by a vector x[0…ncols-1]
    VecDoub atx(constVecDoub &x) const;                //multiply A transpose by a vector x[0…nrows-1]
        NRsparseMat transpose() const;                    //form A transpose
    };
    NRsparseMat::NRsparseMat() : nrows(0),ncols(0),nvals(0),col_ptr(),
        row_ind(),val() {}
    NRsparseMat::NRsparseMat(Int m,Int n,Int nnvals) : nrows(m),ncols(n),
        nvals(nnvals),col_ptr(n+1,0),row_ind(nnvals,0),val(nnvals,0.0) {}
    

  2. #2
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    249
    It would help immensely if you could tell us exactly what line the compiler complains about.

    P.S. Never mind, you can't assign values like that outside of a function

    Code:
    NRsparseMatmy_A;
    my_A.nrows = M;     ** Error **
    my_A.ncols = N;     ** Error **
    my_A.nvals = M*N;   ** Error **
    You're going to have to move the assignments into a function.

    P.S. #2: Global variables should be avoided like the plague anyway (global constants are fine).
    Last edited by antred; 06-01-2012 at 03:16 PM.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,302
    It is not possible to have assignment statements (eg my_A.nrows = M;) at file scope. Such statements need to be in the body of functions (they are executed when the program is run, not at compile time).
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6
    Thanks for the help. That fixed my issue.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-15-2011, 02:47 PM
  2. Expected constructor, destructor, type conversion
    By SterlingM in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2010, 01:16 PM
  3. Replies: 10
    Last Post: 03-07-2010, 11:20 PM
  4. expected constructor, destructor, or type conversion before '('
    By cosmiccomputing in forum C Programming
    Replies: 5
    Last Post: 06-16-2008, 11:03 PM
  5. error: expected ‘;’ before ‘:’ token
    By kris.c in forum C Programming
    Replies: 5
    Last Post: 02-10-2008, 09:26 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21