CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Variables inside classes

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 12, 2010, 11:30
Default Variables inside classes
  #1
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 15
tonyuprm is on a distinguished road
Hi all,

I'm creating a class but I cannot declare variables inside my class to then use them in my member functions. Here is the error I get.

const scalar pi2=3.14;

error: ISO C++ forbids initialization of member âpi2â
error: making âpi2â static
tonyuprm is offline   Reply With Quote

Old   July 13, 2010, 02:27
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by tonyuprm View Post
Hi all,

I'm creating a class but I cannot declare variables inside my class to then use them in my member functions. Here is the error I get.

const scalar pi2=3.14;

error: ISO C++ forbids initialization of member âpi2â
error: making âpi2â static
Like the error message says, you'll need to make the data member static, which means it is the same for every instance.

Code:
static const scalar pi2 = 3.14;
Note that in-header initialization only works for simple types, for more complex types you need to initialize them in the .C file.

BTW: if you really just need PI, you could also consider using the constants provided with OpenFOAM:
http://foam.sourceforge.net/doc/Doxy...stants_8H.html
olesen is offline   Reply With Quote

Old   July 13, 2010, 13:16
Default
  #3
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 15
tonyuprm is on a distinguished road
That worked just fine. Thanks!
tonyuprm is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
Modelling the Heat flow inside the curing oven Marios Vlad CFX 1 February 6, 2008 07:11
meshing F1 front wing Steve FLUENT 0 April 17, 2003 12:37
PHI file structure Eugene Phoenics 9 November 2, 2001 22:00
Parallel Computing Classes at San Diego Supercomputer Center Jan. 20-22 Amitava Majumdar Main CFD Forum 0 January 5, 1999 12:00


All times are GMT -4. The time now is 16:55.