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

Variables inside classes

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   July 12, 2010, 11:30
Default Variables inside classes
  #1
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 7
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: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
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: 7
tonyuprm is on a distinguished road
That worked just fine. Thanks!
tonyuprm is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
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 20:08
Modelling the Heat flow inside the curing oven Marios Vlad CFX 1 February 6, 2008 08:11
meshing F1 front wing Steve FLUENT 0 April 17, 2003 12:37
PHI file structure Eugene Phoenics 9 November 2, 2001 23:00
Parallel Computing Classes at San Diego Supercomputer Center Jan. 20-22 Amitava Majumdar Main CFD Forum 0 January 5, 1999 13:00


All times are GMT -4. The time now is 15:45.